diff options
author | Perttu Ahola <celeron55@gmail.com> | 2011-12-02 02:01:46 +0200 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2011-12-02 02:01:46 +0200 |
commit | a416cf7c45d6e23811d4de5a460caf977771eb53 (patch) | |
tree | b40d7b0fd8f878c171c5fec69dc514f2608e9114 | |
parent | 09010410cf8a1b68f3042e07ac6bbda99cc15d02 (diff) | |
download | minetest-a416cf7c45d6e23811d4de5a460caf977771eb53.tar.gz minetest-a416cf7c45d6e23811d4de5a460caf977771eb53.tar.bz2 minetest-a416cf7c45d6e23811d4de5a460caf977771eb53.zip |
Enforce PLAYER_INVENTORY_SIZE in ObjectRef::l_inventory_set_list
-rw-r--r-- | src/scriptapi.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 40e31bb9f..359c14482 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -400,7 +400,7 @@ static void setfloatfield(lua_State *L, int table, */ static void inventory_set_list_from_lua(Inventory *inv, const char *name, - lua_State *L, int tableindex, IGameDef *gamedef) + lua_State *L, int tableindex, IGameDef *gamedef, int forcesize=-1) { // If nil, delete list if(lua_isnil(L, tableindex)){ @@ -424,6 +424,8 @@ static void inventory_set_list_from_lua(Inventory *inv, const char *name, int index = 0; for(std::list<std::string>::const_iterator i = items.begin(); i != items.end(); i++){ + if(forcesize != -1 && index == forcesize) + break; const std::string &itemstring = *i; InventoryItem *newitem = NULL; if(itemstring != "") @@ -433,6 +435,11 @@ static void inventory_set_list_from_lua(Inventory *inv, const char *name, delete olditem; index++; } + while(forcesize != -1 && index < forcesize){ + InventoryItem *olditem = invlist->changeItem(index, NULL); + delete olditem; + index++; + } } static void inventory_get_list_to_lua(Inventory *inv, const char *name, @@ -455,7 +462,7 @@ static void inventory_get_list_to_lua(Inventory *inv, const char *name, lua_pushvalue(L, table_insert); lua_pushvalue(L, table); if(item == NULL){ - lua_pushnil(L); + lua_pushstring(L, ""); } else { lua_pushstring(L, item->getItemString().c_str()); } @@ -1970,7 +1977,7 @@ private: const char *name = lua_tostring(L, 2); // Do it inventory_set_list_from_lua(&player->inventory, name, L, 3, - player->getEnv()->getGameDef()); + player->getEnv()->getGameDef(), PLAYER_INVENTORY_SIZE); player->m_inventory_not_sent = true; return 0; } |