summaryrefslogtreecommitdiff
path: root/src/script/cpp_api
diff options
context:
space:
mode:
authorred-001 <red-001@outlook.ie>2017-01-24 16:26:15 +0000
committerLoïc Blot <nerzhul@users.noreply.github.com>2017-03-13 23:56:05 +0100
commitc42c53fccf87a3819ca78de52f8f20c47c4fbb9f (patch)
tree223bb0b18e989cfe7eb8f7d712bd606976be2c77 /src/script/cpp_api
parent2c19d51409ca903021e0b508e5bc15299c4e51dc (diff)
downloadminetest-c42c53fccf87a3819ca78de52f8f20c47c4fbb9f.tar.gz
minetest-c42c53fccf87a3819ca78de52f8f20c47c4fbb9f.tar.bz2
minetest-c42c53fccf87a3819ca78de52f8f20c47c4fbb9f.zip
[CSM] Add local formspecs. (#5094)
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