summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_inventory.cpp
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2014-06-13 17:07:42 -0400
committerShadowNinja <shadowninja@minetest.net>2014-06-23 15:28:48 -0400
commitd9de29fa50a7d264d68f2530f0b57ada0f8b4903 (patch)
tree35cce910cc617a8199520ba292cbb08c16f02b35 /src/script/lua_api/l_inventory.cpp
parent5fb8778e28beb256513a5c8c20a803066c625c76 (diff)
downloadminetest-d9de29fa50a7d264d68f2530f0b57ada0f8b4903.tar.gz
minetest-d9de29fa50a7d264d68f2530f0b57ada0f8b4903.tar.bz2
minetest-d9de29fa50a7d264d68f2530f0b57ada0f8b4903.zip
Clear inventory before setting lists
Diffstat (limited to 'src/script/lua_api/l_inventory.cpp')
-rw-r--r--src/script/lua_api/l_inventory.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/script/lua_api/l_inventory.cpp b/src/script/lua_api/l_inventory.cpp
index a45ae5168..f48f6083b 100644
--- a/src/script/lua_api/l_inventory.cpp
+++ b/src/script/lua_api/l_inventory.cpp
@@ -271,19 +271,20 @@ int InvRef::l_set_lists(lua_State *L)
if (!inv) {
return 0;
}
+
+ // Make a temporary inventory in case reading fails
+ Inventory *tempInv(inv);
+ tempInv->clear();
+
+ Server *server = getServer(L);
+
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));
- }
+ const char *listname = lua_tostring(L, -2);
+ read_inventory_list(L, -1, tempInv, listname, server);
lua_pop(L, 1);
}
+ inv = tempInv;
return 0;
}