aboutsummaryrefslogtreecommitdiff
path: root/src/script/common/c_content.cpp
diff options
context:
space:
mode:
authorDS <vorunbekannt75@web.de>2022-03-29 18:06:16 +0200
committerGitHub <noreply@github.com>2022-03-29 18:06:16 +0200
commit8d387433b14791db95e59127b5e6e30f58155c1e (patch)
treef7ce345cb892a6c9fdc0f210559e744c57e1f0d4 /src/script/common/c_content.cpp
parent0f25fa7af655b98fa401176a523f269c843d1943 (diff)
downloadminetest-8d387433b14791db95e59127b5e6e30f58155c1e.tar.gz
minetest-8d387433b14791db95e59127b5e6e30f58155c1e.tar.bz2
minetest-8d387433b14791db95e59127b5e6e30f58155c1e.zip
Fix the documentation of InvRef:get_lists() and clean up code (#12150)
Diffstat (limited to 'src/script/common/c_content.cpp')
-rw-r--r--src/script/common/c_content.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index b6eaa6b13..36f4316ee 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -1351,17 +1351,22 @@ void push_tool_capabilities(lua_State *L,
}
/******************************************************************************/
-void push_inventory_list(lua_State *L, Inventory *inv, const char *name)
+void push_inventory_list(lua_State *L, const InventoryList &invlist)
{
- InventoryList *invlist = inv->getList(name);
- if(invlist == NULL){
- lua_pushnil(L);
- return;
+ push_items(L, invlist.getItems());
+}
+
+/******************************************************************************/
+void push_inventory_lists(lua_State *L, const Inventory &inv)
+{
+ const auto &lists = inv.getLists();
+ lua_createtable(L, 0, lists.size());
+ for(const InventoryList *list : lists) {
+ const std::string &name = list->getName();
+ lua_pushlstring(L, name.c_str(), name.size());
+ push_inventory_list(L, *list);
+ lua_rawset(L, -3);
}
- std::vector<ItemStack> items;
- for(u32 i=0; i<invlist->getSize(); i++)
- items.push_back(invlist->getItem(i));
- push_items(L, items);
}
/******************************************************************************/