aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
authorPaul Ouellette <oue.paul18@gmail.com>2019-08-24 12:38:02 -0400
committersfan5 <sfan5@live.de>2019-08-24 18:38:02 +0200
commit008b80fe1ca9d46610b8971e2ac92fb56da8e69f (patch)
tree581fb878e5b5afe163c12dfc926158b9f0e5b0a8 /src/script/lua_api
parentefbac7e4466ebc576b2cc64b5b782c61136cde66 (diff)
downloadminetest-008b80fe1ca9d46610b8971e2ac92fb56da8e69f.tar.gz
minetest-008b80fe1ca9d46610b8971e2ac92fb56da8e69f.tar.bz2
minetest-008b80fe1ca9d46610b8971e2ac92fb56da8e69f.zip
Add ItemStack:get_description() to get tooltip (#8847)
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_item.cpp11
-rw-r--r--src/script/lua_api/l_item.h3
2 files changed, 14 insertions, 0 deletions
diff --git a/src/script/lua_api/l_item.cpp b/src/script/lua_api/l_item.cpp
index e41d23fd1..f9708b560 100644
--- a/src/script/lua_api/l_item.cpp
+++ b/src/script/lua_api/l_item.cpp
@@ -175,6 +175,16 @@ int LuaItemStack::l_set_metadata(lua_State *L)
return 1;
}
+// get_description(self)
+int LuaItemStack::l_get_description(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ LuaItemStack *o = checkobject(L, 1);
+ std::string desc = o->m_stack.getDescription(getGameDef(L)->idef());
+ lua_pushstring(L, desc.c_str());
+ return 1;
+}
+
// clear(self) -> true
int LuaItemStack::l_clear(lua_State *L)
{
@@ -470,6 +480,7 @@ const luaL_Reg LuaItemStack::methods[] = {
luamethod(LuaItemStack, get_meta),
luamethod(LuaItemStack, get_metadata),
luamethod(LuaItemStack, set_metadata),
+ luamethod(LuaItemStack, get_description),
luamethod(LuaItemStack, clear),
luamethod(LuaItemStack, replace),
luamethod(LuaItemStack, to_string),
diff --git a/src/script/lua_api/l_item.h b/src/script/lua_api/l_item.h
index 5ff715b2a..6fab58045 100644
--- a/src/script/lua_api/l_item.h
+++ b/src/script/lua_api/l_item.h
@@ -66,6 +66,9 @@ private:
// set_metadata(self, string)
static int l_set_metadata(lua_State *L);
+ // get_description(self)
+ static int l_get_description(lua_State *L);
+
// clear(self) -> true
static int l_clear(lua_State *L);