Skip to content

Commit

Permalink
Clear inventory before setting lists
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowNinja committed Jun 23, 2014
1 parent 5fb8778 commit d9de29f
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/script/lua_api/l_inventory.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -271,19 +271,20 @@ int InvRef::l_set_lists(lua_State *L)
if (!inv) { if (!inv) {
return 0; return 0;
} }

// Make a temporary inventory in case reading fails
Inventory *tempInv(inv);
tempInv->clear();

Server *server = getServer(L);

lua_pushnil(L); lua_pushnil(L);
while (lua_next(L, 2)) { while (lua_next(L, 2)) {
const char* listname = lua_tostring(L, -2); const char *listname = lua_tostring(L, -2);
InventoryList *list = inv->getList(listname); read_inventory_list(L, -1, tempInv, listname, server);
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); lua_pop(L, 1);
} }
inv = tempInv;
return 0; return 0;
} }


Expand Down

0 comments on commit d9de29f

Please sign in to comment.