Add ObjectRef:get_inventory() and add stuff to documentation comments
authorPerttu Ahola <celeron55@gmail.com>
Tue, 6 Dec 2011 16:59:52 +0000 (18:59 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Mon, 2 Jan 2012 00:59:14 +0000 (02:59 +0200)
data/mods/default/init.lua
src/scriptapi.cpp

index abbeab5d5527aa62b6b677a8827ec1d2944efb40..2b92aef5a931c84798b0d1a7830c7932905c717f 100644 (file)
 -- minetest.chat_send_all(text)
 -- minetest.chat_send_player(name, text)
 -- minetest.get_player_privs(name) -> set of privs
+-- minetest.get_inventory(location) -> InvRef
 -- minetest.get_modpath(modname) -> eg. "/home/user/.minetest/usermods/modname"
+-- ^ location = eg. {type="player", name="celeron55"}
+--                  {type="node", pos={x=, y=, z=}}
 --
 -- stackstring_take_item(stackstring) -> stackstring, item
 -- stackstring_put_item(stackstring, item) -> stackstring, success
 -- - inventory_get_list(name) -> {item1, item2, ...}
 -- - get_look_dir(): get camera direction as a unit vector
 -- - get_look_pitch(): pitch in radians
+--
 -- - get_look_yaw(): yaw in radians (wraps around pretty randomly as of now)
+-- InvRef
+-- - get_size(listname): get size of a list
+-- - set_size(listname, size): set size of a list
+-- - get_stack(listname, i): get a copy of stack index i in list
+-- - set_stack(listname, i, stack): copy stack to index i in list
+-- - get_list(listname): return full list
+-- - set_list(listname, list): set full list (size will not change)
+-- - autoinsert_stack(listname, stack): insert stack somewhere in list
+-- - autoinsert_stackstring(listname, stackstring)
+--
+-- ItemStack
+-- - peek_item(): return item from stack without removing it
+-- - take_item(): remove item from stack and return it
+-- - put_item(): put item in stack; return false if not possible
+-- - put_stackstring(): put stackstring in stack; return false if not possible
 --
 -- Registered entities:
 -- - Functions receive a "luaentity" as self:
index c6a44c914791b8f0fd6102b3d259b73c786cc099..4dcb66c772812445f4da700f0a359a12e0f944a1 100644 (file)
@@ -2005,9 +2005,21 @@ private:
                return 1;
        }
        
-       // inventory_set_list(self, name, {item1, item2, ...})
+       // get_inventory(self)
+       static int l_get_inventory(lua_State *L)
+       {
+               ObjectRef *ref = checkobject(L, 1);
+               ServerRemotePlayer *player = getplayer(ref);
+               if(player == NULL) return 0;
+               // Do it
+               InvRef::createPlayer(L, player);
+               return 1;
+       }
+
+       // deprecated: inventory_set_list(self, name, {item1, item2, ...})
        static int l_inventory_set_list(lua_State *L)
        {
+               infostream<<"Deprecated: inventory_set_list"<<std::endl;
                ObjectRef *ref = checkobject(L, 1);
                ServerRemotePlayer *player = getplayer(ref);
                if(player == NULL) return 0;
@@ -2019,9 +2031,10 @@ private:
                return 0;
        }
 
-       // inventory_get_list(self, name)
+       // deprecated: inventory_get_list(self, name)
        static int l_inventory_get_list(lua_State *L)
        {
+               infostream<<"Deprecated: inventory_get_list"<<std::endl;
                ObjectRef *ref = checkobject(L, 1);
                ServerRemotePlayer *player = getplayer(ref);
                if(player == NULL) return 0;
@@ -2179,8 +2192,9 @@ const luaL_reg ObjectRef::methods[] = {
        method(ObjectRef, setsprite),
        // Player-only
        method(ObjectRef, get_player_name),
-       method(ObjectRef, inventory_set_list),
-       method(ObjectRef, inventory_get_list),
+       method(ObjectRef, get_inventory),
+       method(ObjectRef, inventory_set_list), // deprecated
+       method(ObjectRef, inventory_get_list), // deprecated
        method(ObjectRef, get_wielded_itemstring),
        method(ObjectRef, get_wielded_item),
        method(ObjectRef, get_look_dir),