aboutsummaryrefslogtreecommitdiff
path: root/src/scriptapi.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2013-01-02 22:53:55 +0200
committerPerttu Ahola <celeron55@gmail.com>2013-01-02 22:53:55 +0200
commit69bd803a3221bf02672431390e672b0510695254 (patch)
treee5f216cde7b0f401faa31e2530dff6b5f6574708 /src/scriptapi.cpp
parentb7de864f2e2cc7bc45c39c4ce811dbec0aa7f98a (diff)
downloadminetest-69bd803a3221bf02672431390e672b0510695254.tar.gz
minetest-69bd803a3221bf02672431390e672b0510695254.tar.bz2
minetest-69bd803a3221bf02672431390e672b0510695254.zip
Add InvRef:get_location()
Diffstat (limited to 'src/scriptapi.cpp')
-rw-r--r--src/scriptapi.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp
index 83987fc9b..a79622db3 100644
--- a/src/scriptapi.cpp
+++ b/src/scriptapi.cpp
@@ -2049,6 +2049,43 @@ private:
return 1;
}
+ // get_location() -> location (like minetest.get_inventory(location))
+ static int l_get_location(lua_State *L)
+ {
+ InvRef *ref = checkobject(L, 1);
+ const InventoryLocation &loc = ref->m_loc;
+ switch(loc.type){
+ case InventoryLocation::PLAYER:
+ lua_newtable(L);
+ lua_pushstring(L, "player");
+ lua_setfield(L, -2, "type");
+ lua_pushstring(L, loc.name.c_str());
+ lua_setfield(L, -2, "name");
+ return 1;
+ case InventoryLocation::NODEMETA:
+ lua_newtable(L);
+ lua_pushstring(L, "nodemeta");
+ lua_setfield(L, -2, "type");
+ push_v3s16(L, loc.p);
+ lua_setfield(L, -2, "name");
+ return 1;
+ case InventoryLocation::DETACHED:
+ lua_newtable(L);
+ lua_pushstring(L, "detached");
+ lua_setfield(L, -2, "type");
+ lua_pushstring(L, loc.name.c_str());
+ lua_setfield(L, -2, "name");
+ return 1;
+ case InventoryLocation::UNDEFINED:
+ case InventoryLocation::CURRENT_PLAYER:
+ break;
+ }
+ lua_newtable(L);
+ lua_pushstring(L, "undefined");
+ lua_setfield(L, -2, "type");
+ return 1;
+ }
+
public:
InvRef(const InventoryLocation &loc):
m_loc(loc)
@@ -2124,6 +2161,7 @@ const luaL_reg InvRef::methods[] = {
method(InvRef, room_for_item),
method(InvRef, contains_item),
method(InvRef, remove_item),
+ method(InvRef, get_location),
{0,0}
};