diff options
author | Perttu Ahola <celeron55@gmail.com> | 2011-12-06 16:22:08 +0200 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2012-01-02 02:59:14 +0200 |
commit | 270a482740c4b3e8367043abfb0e77367d55a592 (patch) | |
tree | 5514a8546ed3715dd3cda20b46aafab483548136 | |
parent | e0b4890794497c4b801e901fa233bbb2589e0503 (diff) | |
download | minetest-270a482740c4b3e8367043abfb0e77367d55a592.tar.gz minetest-270a482740c4b3e8367043abfb0e77367d55a592.tar.bz2 minetest-270a482740c4b3e8367043abfb0e77367d55a592.zip |
Add InvRef:get_list() and InvRef:set_list() and fix some things (untested)
-rw-r--r-- | src/scriptapi.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index f30aab41c..101e07894 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -1042,6 +1042,7 @@ private: Inventory *inv = getinv(L, ref); if(newsize == 0){ inv->deleteList(listname); + reportInventoryChange(L, ref); return 0; } InventoryList *list = inv->getList(listname); @@ -1050,6 +1051,7 @@ private: } else { list = inv->addList(listname, newsize); } + reportInventoryChange(L, ref); return 0; } @@ -1085,9 +1087,37 @@ private: bool success = (olditem != newitem); delete olditem; lua_pushboolean(L, success); + reportInventoryChange(L, ref); return 1; } + // get_list(self, listname) -> list or nil + static int l_get_list(lua_State *L) + { + InvRef *ref = checkobject(L, 1); + const char *listname = luaL_checkstring(L, 2); + Inventory *inv = getinv(L, ref); + inventory_get_list_to_lua(inv, listname, L); + return 1; + } + + // set_list(self, listname, list) + static int l_set_list(lua_State *L) + { + InvRef *ref = checkobject(L, 1); + const char *listname = luaL_checkstring(L, 2); + Inventory *inv = getinv(L, ref); + InventoryList *list = inv->getList(listname); + if(list) + inventory_set_list_from_lua(inv, listname, L, 3, + get_server(L), list->getSize()); + else + inventory_set_list_from_lua(inv, listname, L, 3, + get_server(L)); + reportInventoryChange(L, ref); + return 0; + } + public: InvRef(const InventoryLocation &loc): m_loc(loc) @@ -1154,6 +1184,8 @@ const luaL_reg InvRef::methods[] = { method(InvRef, set_size), method(InvRef, get_stack), method(InvRef, set_stack), + method(InvRef, get_list), + method(InvRef, set_list), {0,0} }; |