1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Fix the documentation of InvRef:get_lists() and clean up code (#12150)

This commit is contained in:
DS 2022-03-29 18:06:16 +02:00 committed by GitHub
parent 0f25fa7af6
commit 8d387433b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 56 additions and 96 deletions

View file

@ -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);
}
/******************************************************************************/