diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 83987fc..b130863 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -2049,6 +2049,40 @@ class InvRef 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::UNDEFINED: + case InventoryLocation::CURRENT_PLAYER: + return 0; + 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; + } + return 0; + } + public: InvRef(const InventoryLocation &loc): m_loc(loc)