diff --git a/doc/lua_api.txt b/doc/lua_api.txt
index ebad1dad2c62ceaca1319afd8272659e9e51314c..124344cadc807f02a57907fe74751aee9874e008 100644
--- a/doc/lua_api.txt
+++ b/doc/lua_api.txt
@@ -1231,6 +1231,8 @@ methods:
     can be fully taken from the list
   remove_item(listname, stack): take as many items as specified from the list,
     returns the items that were actually removed (as an ItemStack)
+- get_location() -> location compatible to minetest.get_inventory(location)
+                 -> {type="undefined"} in case location is not known
 
 ItemStack: A stack of items.
 - Can be created via ItemStack(itemstack or itemstring or table or nil)
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp
index 83987fc9b477818014906895b9eed52480f20641..a79622db327020e2d9edfd769250c16ed4daabb9 100644
--- a/src/scriptapi.cpp
+++ b/src/scriptapi.cpp
@@ -2049,6 +2049,43 @@ 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::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}
 };