diff options
author | Perttu Ahola <celeron55@gmail.com> | 2012-07-22 17:10:58 +0300 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2012-07-22 17:40:48 +0300 |
commit | 4cc98d7add7b697ac302a6136bbeb95ef78cec45 (patch) | |
tree | efcdd9352f25c99557a1acd5177b6d586ecba881 /src/scriptapi.cpp | |
parent | 506203345ba2795aa0af68a434f4b77cf50e664a (diff) | |
download | hax-minetest-server-4cc98d7add7b697ac302a6136bbeb95ef78cec45.tar.gz hax-minetest-server-4cc98d7add7b697ac302a6136bbeb95ef78cec45.zip |
minetest.register_on_player_receive_fields()
Diffstat (limited to '')
-rw-r--r-- | src/scriptapi.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index a72e66b4f..6cb701689 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -5239,6 +5239,40 @@ bool scriptapi_set_password(lua_State *L, const std::string &playername, } /* + player +*/ + +void scriptapi_on_player_receive_fields(lua_State *L, + ServerActiveObject *player, + const std::string &formname, + const std::map<std::string, std::string> &fields) +{ + realitycheck(L); + assert(lua_checkstack(L, 20)); + StackUnroller stack_unroller(L); + + // Get minetest.registered_on_chat_messages + lua_getglobal(L, "minetest"); + lua_getfield(L, -1, "registered_on_player_receive_fields"); + // Call callbacks + // param 1 + objectref_get_or_create(L, player); + // param 2 + lua_pushstring(L, formname.c_str()); + // param 3 + lua_newtable(L); + for(std::map<std::string, std::string>::const_iterator + i = fields.begin(); i != fields.end(); i++){ + const std::string &name = i->first; + const std::string &value = i->second; + lua_pushstring(L, name.c_str()); + lua_pushlstring(L, value.c_str(), value.size()); + lua_settable(L, -3); + } + scriptapi_run_callbacks(L, 3, RUN_CALLBACKS_MODE_OR_SC); +} + +/* item callbacks and node callbacks */ |