diff --git a/src/script/lua_api/l_inventory.cpp b/src/script/lua_api/l_inventory.cpp index d1c357329..f5c5e4d54 100644 --- a/src/script/lua_api/l_inventory.cpp +++ b/src/script/lua_api/l_inventory.cpp @@ -96,38 +96,37 @@ int InvRef::l_set_size(lua_State *L) NO_MAP_LOCK_REQUIRED; InvRef *ref = checkObject(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(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