diff options
author | ShadowNinja <shadowninja@minetest.net> | 2014-04-15 13:30:46 -0400 |
---|---|---|
committer | ShadowNinja <shadowninja@minetest.net> | 2014-04-27 16:15:53 -0400 |
commit | db4ea4658c58772ee447ff0eff8bb39b692081ec (patch) | |
tree | 0ef394ea43e667bff1660bb576fe4f9013ce404b /src/script/cpp_api/s_mainmenu.cpp | |
parent | 1838a3fd696782b1733a435bbb25accf3e40d1f3 (diff) | |
download | minetest-db4ea4658c58772ee447ff0eff8bb39b692081ec.tar.gz minetest-db4ea4658c58772ee447ff0eff8bb39b692081ec.tar.bz2 minetest-db4ea4658c58772ee447ff0eff8bb39b692081ec.zip |
Only push the Lua error handler once
Diffstat (limited to 'src/script/cpp_api/s_mainmenu.cpp')
-rw-r--r-- | src/script/cpp_api/s_mainmenu.cpp | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/src/script/cpp_api/s_mainmenu.cpp b/src/script/cpp_api/s_mainmenu.cpp index 5c54f7368..62baeb406 100644 --- a/src/script/cpp_api/s_mainmenu.cpp +++ b/src/script/cpp_api/s_mainmenu.cpp @@ -37,14 +37,11 @@ void ScriptApiMainMenu::handleMainMenuEvent(std::string text) { SCRIPTAPI_PRECHECKHEADER - lua_pushcfunction(L, script_error_handler); - int errorhandler = lua_gettop(L); - // Get handler function lua_getglobal(L, "engine"); lua_getfield(L, -1, "event_handler"); lua_remove(L, -2); // Remove engine - if(lua_isnil(L, -1)) { + if (lua_isnil(L, -1)) { lua_pop(L, 1); // Pop event_handler return; } @@ -52,41 +49,37 @@ void ScriptApiMainMenu::handleMainMenuEvent(std::string text) // Call it lua_pushstring(L, text.c_str()); - if(lua_pcall(L, 1, 0, errorhandler)) + if (lua_pcall(L, 1, 0, m_errorhandler)) scriptError(); - lua_pop(L, 1); // Pop error handler } void ScriptApiMainMenu::handleMainMenuButtons(std::map<std::string, std::string> fields) { SCRIPTAPI_PRECHECKHEADER - lua_pushcfunction(L, script_error_handler); - int errorhandler = lua_gettop(L); - // Get handler function lua_getglobal(L, "engine"); lua_getfield(L, -1, "button_handler"); lua_remove(L, -2); // Remove engine - if(lua_isnil(L, -1)) { + if (lua_isnil(L, -1)) { lua_pop(L, 1); // Pop button handler return; } luaL_checktype(L, -1, LUA_TFUNCTION); - // Convert fields to lua table + // Convert fields to a Lua table 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; + std::map<std::string, std::string>::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); } // Call it - if(lua_pcall(L, 1, 0, errorhandler)) + if (lua_pcall(L, 1, 0, m_errorhandler)) scriptError(); - lua_pop(L, 1); // Pop error handler } + |