summaryrefslogtreecommitdiff
path: root/src/script/cpp_api/s_mainmenu.cpp
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2013-11-05 12:06:15 -0500
committerShadowNinja <shadowninja@minetest.net>2013-11-15 14:13:31 -0500
commit371b39a09a0bf248d674fae718f5ff369e895b66 (patch)
treeda8bb27e27a9c89eac895d211721de11a3781533 /src/script/cpp_api/s_mainmenu.cpp
parent3f519eb72922607329e1e6a48768d84d1f443efc (diff)
downloadminetest-371b39a09a0bf248d674fae718f5ff369e895b66.tar.gz
minetest-371b39a09a0bf248d674fae718f5ff369e895b66.tar.bz2
minetest-371b39a09a0bf248d674fae718f5ff369e895b66.zip
Pass a errfunc to lua_pcall to get a traceback
Diffstat (limited to 'src/script/cpp_api/s_mainmenu.cpp')
-rw-r--r--src/script/cpp_api/s_mainmenu.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/script/cpp_api/s_mainmenu.cpp b/src/script/cpp_api/s_mainmenu.cpp
index af92c59a9..5c54f7368 100644
--- a/src/script/cpp_api/s_mainmenu.cpp
+++ b/src/script/cpp_api/s_mainmenu.cpp
@@ -37,29 +37,41 @@ 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");
- if(lua_isnil(L, -1))
+ lua_remove(L, -2); // Remove engine
+ if(lua_isnil(L, -1)) {
+ lua_pop(L, 1); // Pop event_handler
return;
+ }
luaL_checktype(L, -1, LUA_TFUNCTION);
// Call it
lua_pushstring(L, text.c_str());
- if(lua_pcall(L, 1, 0, 0))
- scriptError("error running function engine.event_handler: %s\n",
- lua_tostring(L, -1));
+ if(lua_pcall(L, 1, 0, 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");
- if(lua_isnil(L, -1))
+ lua_remove(L, -2); // Remove engine
+ if(lua_isnil(L, -1)) {
+ lua_pop(L, 1); // Pop button handler
return;
+ }
luaL_checktype(L, -1, LUA_TFUNCTION);
// Convert fields to lua table
@@ -74,7 +86,7 @@ void ScriptApiMainMenu::handleMainMenuButtons(std::map<std::string, std::string>
}
// Call it
- if(lua_pcall(L, 1, 0, 0))
- scriptError("error running function engine.button_handler: %s\n",
- lua_tostring(L, -1));
+ if(lua_pcall(L, 1, 0, errorhandler))
+ scriptError();
+ lua_pop(L, 1); // Pop error handler
}