summaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
authorbigfoot547 <bigfoot547@users.noreply.github.com>2017-05-21 07:40:55 -0500
committerLoïc Blot <nerzhul@users.noreply.github.com>2017-05-21 14:40:55 +0200
commitdfa0c15ce045705f05487d623dc7beca6c945b4b (patch)
tree20f8e1beed4524f4f92e5a6af52c7b01eb8ef7ac /src/script/lua_api
parentae483f1bd00625216bb0a35370f0cc4568ad7893 (diff)
downloadminetest-dfa0c15ce045705f05487d623dc7beca6c945b4b.tar.gz
minetest-dfa0c15ce045705f05487d623dc7beca6c945b4b.tar.bz2
minetest-dfa0c15ce045705f05487d623dc7beca6c945b4b.zip
[CSM] Add function to get the definition of items (#5732)
Add node def and item def documentation. Please be ready for merge!
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_client.cpp47
-rw-r--r--src/script/lua_api/l_client.h10
2 files changed, 56 insertions, 1 deletions
diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp
index 22045e06d..87cfa00fe 100644
--- a/src/script/lua_api/l_client.cpp
+++ b/src/script/lua_api/l_client.cpp
@@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mainmenumanager.h"
#include "map.h"
#include "util/string.h"
+#include "nodedef.h"
extern MainGameCallback *g_gamecallback;
@@ -260,6 +261,50 @@ int ModApiClient::l_get_server_info(lua_State *L)
return 1;
}
+// get_item_def(itemstring)
+int ModApiClient::l_get_item_def(lua_State *L)
+{
+ IGameDef *gdef = getGameDef(L);
+ assert(gdef);
+
+ IItemDefManager *idef = gdef->idef();
+ assert(idef);
+
+ if (!lua_isstring(L, 1))
+ return 0;
+
+ const std::string &name(lua_tostring(L, 1));
+ if (!idef->isKnown(name))
+ return 0;
+ const ItemDefinition &def = idef->get(name);
+
+ push_item_definition_full(L, def);
+
+ return 1;
+}
+
+// get_node_def(nodename)
+int ModApiClient::l_get_node_def(lua_State *L)
+{
+ IGameDef *gdef = getGameDef(L);
+ assert(gdef);
+
+ INodeDefManager *ndef = gdef->ndef();
+ assert(ndef);
+
+ if (!lua_isstring(L, 1))
+ return 0;
+
+ const std::string &name = lua_tostring(L, 1);
+ const ContentFeatures &cf = ndef->get(ndef->getId(name));
+ if (cf.name != name) // Unknown node. | name = <whatever>, cf.name = ignore
+ return 0;
+
+ push_content_features(L, cf);
+
+ return 1;
+}
+
int ModApiClient::l_take_screenshot(lua_State *L)
{
Client *client = getClient(L);
@@ -286,5 +331,7 @@ void ModApiClient::Initialize(lua_State *L, int top)
API_FCT(sound_play);
API_FCT(sound_stop);
API_FCT(get_server_info);
+ API_FCT(get_item_def);
+ API_FCT(get_node_def);
API_FCT(take_screenshot);
}
diff --git a/src/script/lua_api/l_client.h b/src/script/lua_api/l_client.h
index 2267a4c9d..9813a5604 100644
--- a/src/script/lua_api/l_client.h
+++ b/src/script/lua_api/l_client.h
@@ -22,6 +22,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define L_CLIENT_H_
#include "lua_api/l_base.h"
+#include "itemdef.h"
+#include "tool.h"
class ModApiClient : public ModApiBase
{
@@ -38,7 +40,7 @@ private:
// get_player_names()
static int l_get_player_names(lua_State *L);
- // show_formspec(name, fornspec)
+ // show_formspec(name, formspec)
static int l_show_formspec(lua_State *L);
// send_respawn()
@@ -74,6 +76,12 @@ private:
// get_server_info()
static int l_get_server_info(lua_State *L);
+
+ // get_item_def(itemstring)
+ static int l_get_item_def(lua_State *L);
+
+ // get_node_def(nodename)
+ static int l_get_node_def(lua_State *L);
static int l_take_screenshot(lua_State *L);