mirror of
https://github.com/moparisthebest/minetest
synced 2024-12-22 23:58:48 -05:00
Add InvRef::get/set_lists()
This commit is contained in:
parent
6f6f289db4
commit
bd8ddf1a52
@ -1761,6 +1761,8 @@ methods:
|
|||||||
- set_stack(listname, i, stack): copy stack to index i in list
|
- set_stack(listname, i, stack): copy stack to index i in list
|
||||||
- get_list(listname): return full list
|
- get_list(listname): return full list
|
||||||
- set_list(listname, list): set full list (size will not change)
|
- set_list(listname, list): set full list (size will not change)
|
||||||
|
- get_lists(): returns list of inventory lists
|
||||||
|
- set_lists(lists): sets inventory lists (size will not change)
|
||||||
- add_item(listname, stack): add item somewhere in list, returns leftover ItemStack
|
- add_item(listname, stack): add item somewhere in list, returns leftover ItemStack
|
||||||
- room_for_item(listname, stack): returns true if the stack of items
|
- room_for_item(listname, stack): returns true if the stack of items
|
||||||
can be fully added to the list
|
can be fully added to the list
|
||||||
|
@ -241,6 +241,52 @@ int InvRef::l_set_list(lua_State *L)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get_lists(self) -> list of InventoryLists
|
||||||
|
int InvRef::l_get_lists(lua_State *L)
|
||||||
|
{
|
||||||
|
NO_MAP_LOCK_REQUIRED;
|
||||||
|
InvRef *ref = checkobject(L, 1);
|
||||||
|
Inventory *inv = getinv(L, ref);
|
||||||
|
if (!inv) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
std::vector<const InventoryList*> lists = inv->getLists();
|
||||||
|
std::vector<const InventoryList*>::iterator iter = lists.begin();
|
||||||
|
lua_createtable(L, 0, lists.size());
|
||||||
|
for (; iter != lists.end(); iter++) {
|
||||||
|
const char* name = (*iter)->getName().c_str();
|
||||||
|
lua_pushstring(L, name);
|
||||||
|
push_inventory_list(L, inv, name);
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set_lists(self, lists)
|
||||||
|
int InvRef::l_set_lists(lua_State *L)
|
||||||
|
{
|
||||||
|
NO_MAP_LOCK_REQUIRED;
|
||||||
|
InvRef *ref = checkobject(L, 1);
|
||||||
|
Inventory *inv = getinv(L, ref);
|
||||||
|
if (!inv) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
lua_pushnil(L);
|
||||||
|
while (lua_next(L, 2)) {
|
||||||
|
const char* listname = lua_tostring(L, -2);
|
||||||
|
InventoryList *list = inv->getList(listname);
|
||||||
|
if (list) {
|
||||||
|
read_inventory_list(L, -1, inv, listname,
|
||||||
|
getServer(L), list->getSize());
|
||||||
|
} else {
|
||||||
|
read_inventory_list(L, -1, inv, listname,
|
||||||
|
getServer(L));
|
||||||
|
}
|
||||||
|
lua_pop(L, 1);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// add_item(self, listname, itemstack or itemstring or table or nil) -> itemstack
|
// add_item(self, listname, itemstack or itemstring or table or nil) -> itemstack
|
||||||
// Returns the leftover stack
|
// Returns the leftover stack
|
||||||
int InvRef::l_add_item(lua_State *L)
|
int InvRef::l_add_item(lua_State *L)
|
||||||
@ -426,6 +472,8 @@ const luaL_reg InvRef::methods[] = {
|
|||||||
luamethod(InvRef, set_stack),
|
luamethod(InvRef, set_stack),
|
||||||
luamethod(InvRef, get_list),
|
luamethod(InvRef, get_list),
|
||||||
luamethod(InvRef, set_list),
|
luamethod(InvRef, set_list),
|
||||||
|
luamethod(InvRef, get_lists),
|
||||||
|
luamethod(InvRef, set_lists),
|
||||||
luamethod(InvRef, add_item),
|
luamethod(InvRef, add_item),
|
||||||
luamethod(InvRef, room_for_item),
|
luamethod(InvRef, room_for_item),
|
||||||
luamethod(InvRef, contains_item),
|
luamethod(InvRef, contains_item),
|
||||||
|
@ -79,6 +79,12 @@ private:
|
|||||||
// set_list(self, listname, list)
|
// set_list(self, listname, list)
|
||||||
static int l_set_list(lua_State *L);
|
static int l_set_list(lua_State *L);
|
||||||
|
|
||||||
|
// get_lists(self) -> list of InventoryLists
|
||||||
|
static int l_get_lists(lua_State *L);
|
||||||
|
|
||||||
|
// set_lists(self, lists)
|
||||||
|
static int l_set_lists(lua_State *L);
|
||||||
|
|
||||||
// add_item(self, listname, itemstack or itemstring or table or nil) -> itemstack
|
// add_item(self, listname, itemstack or itemstring or table or nil) -> itemstack
|
||||||
// Returns the leftover stack
|
// Returns the leftover stack
|
||||||
static int l_add_item(lua_State *L);
|
static int l_add_item(lua_State *L);
|
||||||
|
Loading…
Reference in New Issue
Block a user