From 4cc98d7add7b697ac302a6136bbeb95ef78cec45 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 22 Jul 2012 17:10:58 +0300 Subject: minetest.register_on_player_receive_fields() --- src/scriptapi.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/scriptapi.cpp') diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index a72e66b4f..6cb701689 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -5238,6 +5238,40 @@ bool scriptapi_set_password(lua_State *L, const std::string &playername, return lua_toboolean(L, -1); } +/* + player +*/ + +void scriptapi_on_player_receive_fields(lua_State *L, + ServerActiveObject *player, + const std::string &formname, + const std::map &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::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 */ -- cgit v1.2.3