mirror of
https://github.com/minetest/minetest.git
synced 2025-03-06 20:48:40 +01:00
InvRef: deduplicate code
This commit is contained in:
parent
5419345dff
commit
8caf922df6
1 changed files with 35 additions and 36 deletions
|
@ -96,38 +96,37 @@ int InvRef::l_set_size(lua_State *L)
|
|||
NO_MAP_LOCK_REQUIRED;
|
||||
InvRef *ref = checkObject<InvRef>(L, 1);
|
||||
const char *listname = luaL_checkstring(L, 2);
|
||||
Inventory *inv;
|
||||
InventoryList *list;
|
||||
|
||||
int newsize = luaL_checknumber(L, 3);
|
||||
if (newsize < 0) {
|
||||
lua_pushboolean(L, false);
|
||||
return 1;
|
||||
if (newsize < 0)
|
||||
goto fail;
|
||||
|
||||
inv = getinv(L, ref);
|
||||
if (!inv)
|
||||
goto fail;
|
||||
|
||||
if (newsize == 0) {
|
||||
inv->deleteList(listname);
|
||||
goto done;
|
||||
}
|
||||
|
||||
Inventory *inv = getinv(L, ref);
|
||||
if(inv == NULL){
|
||||
lua_pushboolean(L, false);
|
||||
return 1;
|
||||
}
|
||||
if(newsize == 0){
|
||||
inv->deleteList(listname);
|
||||
reportInventoryChange(L, ref);
|
||||
lua_pushboolean(L, true);
|
||||
return 1;
|
||||
}
|
||||
InventoryList *list = inv->getList(listname);
|
||||
if(list){
|
||||
list = inv->getList(listname);
|
||||
if (list) {
|
||||
list->setSize(newsize);
|
||||
} else {
|
||||
list = inv->addList(listname, newsize);
|
||||
if (!list)
|
||||
{
|
||||
lua_pushboolean(L, false);
|
||||
return 1;
|
||||
}
|
||||
goto fail;
|
||||
}
|
||||
done:
|
||||
reportInventoryChange(L, ref);
|
||||
lua_pushboolean(L, true);
|
||||
return 1;
|
||||
fail:
|
||||
lua_pushboolean(L, false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// set_width(self, listname, size)
|
||||
|
@ -136,28 +135,28 @@ int InvRef::l_set_width(lua_State *L)
|
|||
NO_MAP_LOCK_REQUIRED;
|
||||
InvRef *ref = checkObject<InvRef>(L, 1);
|
||||
const char *listname = luaL_checkstring(L, 2);
|
||||
Inventory *inv;
|
||||
InventoryList *list;
|
||||
|
||||
int newwidth = luaL_checknumber(L, 3);
|
||||
if (newwidth < 0) {
|
||||
lua_pushboolean(L, false);
|
||||
return 1;
|
||||
}
|
||||
if (newwidth < 0)
|
||||
goto fail;
|
||||
|
||||
Inventory *inv = getinv(L, ref);
|
||||
if(inv == NULL){
|
||||
lua_pushboolean(L, false);
|
||||
return 1;
|
||||
}
|
||||
InventoryList *list = inv->getList(listname);
|
||||
if(list){
|
||||
list->setWidth(newwidth);
|
||||
} else {
|
||||
lua_pushboolean(L, false);
|
||||
return 1;
|
||||
}
|
||||
inv = getinv(L, ref);
|
||||
if (!inv)
|
||||
goto fail;
|
||||
|
||||
list = inv->getList(listname);
|
||||
if (!list)
|
||||
goto fail;
|
||||
|
||||
list->setWidth(newwidth);
|
||||
reportInventoryChange(L, ref);
|
||||
lua_pushboolean(L, true);
|
||||
return 1;
|
||||
fail:
|
||||
lua_pushboolean(L, false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// get_stack(self, listname, i) -> itemstack
|
||||
|
|
Loading…
Add table
Reference in a new issue