aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/cpp_api')
-rw-r--r--src/script/cpp_api/s_client.cpp24
-rw-r--r--src/script/cpp_api/s_client.h7
2 files changed, 30 insertions, 1 deletions
diff --git a/src/script/cpp_api/s_client.cpp b/src/script/cpp_api/s_client.cpp
index ce88d67e3..1827d483b 100644
--- a/src/script/cpp_api/s_client.cpp
+++ b/src/script/cpp_api/s_client.cpp
@@ -112,3 +112,27 @@ void ScriptApiClient::environment_step(float dtime)
+ script_get_backtrace(L));
}
}
+
+void ScriptApiClient::on_formspec_input(const std::string &formname,
+ const StringMap &fields)
+{
+ SCRIPTAPI_PRECHECKHEADER
+
+ // Get core.registered_on_chat_messages
+ lua_getglobal(L, "core");
+ lua_getfield(L, -1, "registered_on_formspec_input");
+ // Call callbacks
+ // param 1
+ lua_pushstring(L, formname.c_str());
+ // param 2
+ lua_newtable(L);
+ StringMap::const_iterator it;
+ for (it = fields.begin(); it != fields.end(); ++it) {
+ const std::string &name = it->first;
+ const std::string &value = it->second;
+ lua_pushstring(L, name.c_str());
+ lua_pushlstring(L, value.c_str(), value.size());
+ lua_settable(L, -3);
+ }
+ runCallbacks(2, RUN_CALLBACKS_MODE_OR_SC);
+}
diff --git a/src/script/cpp_api/s_client.h b/src/script/cpp_api/s_client.h
index 3d373f97c..42c41f8a4 100644
--- a/src/script/cpp_api/s_client.h
+++ b/src/script/cpp_api/s_client.h
@@ -22,6 +22,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define S_CLIENT_H_
#include "cpp_api/s_base.h"
+#include "util/string.h"
+
+#ifdef _CRT_MSVCP_CURRENT
+#include <cstdint>
+#endif
class ScriptApiClient: virtual public ScriptApiBase
{
@@ -36,7 +41,7 @@ public:
void on_damage_taken(int32_t damage_amount);
void on_hp_modification(int32_t newhp);
void on_death();
-
void environment_step(float dtime);
+ void on_formspec_input(const std::string &formname, const StringMap &fields);
};
#endif