diff options
author | Perttu Ahola <celeron55@gmail.com> | 2012-06-01 20:51:15 +0300 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2012-06-03 22:31:01 +0300 |
commit | d7447cdf9e4df3c345218886ab2bae0e0cc4fc55 (patch) | |
tree | 4ebc1c2fd91d66f8711ed87013af80a4adf53cc0 /src/scriptapi.cpp | |
parent | ff8d2bbc3682b12d40d1dfb212d39a50c498fb93 (diff) | |
download | minetest-d7447cdf9e4df3c345218886ab2bae0e0cc4fc55.tar.gz minetest-d7447cdf9e4df3c345218886ab2bae0e0cc4fc55.tar.bz2 minetest-d7447cdf9e4df3c345218886ab2bae0e0cc4fc55.zip |
Implement sign using form field protocol
Diffstat (limited to 'src/scriptapi.cpp')
-rw-r--r-- | src/scriptapi.cpp | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 255d37fc2..f9ec58582 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -141,14 +141,14 @@ static Server* get_server(lua_State *L) return server; } -/*static ServerEnvironment* get_env(lua_State *L) +static ServerEnvironment* get_env(lua_State *L) { // Get environment from registry lua_getfield(L, LUA_REGISTRYINDEX, "minetest_env"); ServerEnvironment *env = (ServerEnvironment*)lua_touserdata(L, -1); lua_pop(L, 1); return env; -}*/ +} static void objectref_get(lua_State *L, u16 id) { @@ -4973,6 +4973,47 @@ void scriptapi_node_on_destruct(lua_State *L, v3s16 p, MapNode node) script_error(L, "error: %s", lua_tostring(L, -1)); } +void scriptapi_node_on_receive_fields(lua_State *L, v3s16 p, + const std::string &formname, + const std::map<std::string, std::string> &fields, + ServerActiveObject *sender) +{ + realitycheck(L); + assert(lua_checkstack(L, 20)); + StackUnroller stack_unroller(L); + + INodeDefManager *ndef = get_server(L)->ndef(); + + // If node doesn't exist, we don't know what callback to call + MapNode node = get_env(L)->getMap().getNodeNoEx(p); + if(node.getContent() == CONTENT_IGNORE) + return; + + // Push callback function on stack + if(!get_item_callback(L, ndef->get(node).name.c_str(), "on_receive_fields")) + return; + + // Call function + // param 1 + push_v3s16(L, p); + // 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); + } + // param 4 + objectref_get_or_create(L, sender); + if(lua_pcall(L, 4, 0, 0)) + script_error(L, "error: %s", lua_tostring(L, -1)); +} + /* environment */ |