summaryrefslogtreecommitdiff
path: root/src/script/cpp_api/s_server.cpp
diff options
context:
space:
mode:
authorKahrl <kahrl@gmx.net>2015-08-25 07:44:53 +0200
committerest31 <MTest31@outlook.com>2015-08-27 01:56:06 +0200
commit3304e1e517fb8aac008c4684e72a4b59b408414a (patch)
treeddcc820601c02d6783578b7accc68d35a2d312fc /src/script/cpp_api/s_server.cpp
parent8658c8d9b5f30dc952eed29a19d619de9210474c (diff)
downloadminetest-3304e1e517fb8aac008c4684e72a4b59b408414a.tar.gz
minetest-3304e1e517fb8aac008c4684e72a4b59b408414a.tar.bz2
minetest-3304e1e517fb8aac008c4684e72a4b59b408414a.zip
Push error handler afresh each time lua_pcall is used
Fixes "double fault" / "error in error handling" messages (issue #1423) and instead shows a complete backtrace.
Diffstat (limited to 'src/script/cpp_api/s_server.cpp')
-rw-r--r--src/script/cpp_api/s_server.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/script/cpp_api/s_server.cpp b/src/script/cpp_api/s_server.cpp
index ec2f9c0af..38bd41f87 100644
--- a/src/script/cpp_api/s_server.cpp
+++ b/src/script/cpp_api/s_server.cpp
@@ -27,13 +27,15 @@ bool ScriptApiServer::getAuth(const std::string &playername,
{
SCRIPTAPI_PRECHECKHEADER
+ int error_handler = PUSH_ERROR_HANDLER(L);
getAuthHandler();
lua_getfield(L, -1, "get_auth");
if (lua_type(L, -1) != LUA_TFUNCTION)
throw LuaError("Authentication handler missing get_auth");
lua_pushstring(L, playername.c_str());
- PCALL_RES(lua_pcall(L, 1, 1, m_errorhandler));
+ PCALL_RES(lua_pcall(L, 1, 1, error_handler));
lua_remove(L, -2); // Remove auth handler
+ lua_remove(L, error_handler);
// nil = login not allowed
if (lua_isnil(L, -1))
@@ -99,6 +101,7 @@ void ScriptApiServer::createAuth(const std::string &playername,
{
SCRIPTAPI_PRECHECKHEADER
+ int error_handler = PUSH_ERROR_HANDLER(L);
getAuthHandler();
lua_getfield(L, -1, "create_auth");
lua_remove(L, -2); // Remove auth handler
@@ -106,7 +109,8 @@ void ScriptApiServer::createAuth(const std::string &playername,
throw LuaError("Authentication handler missing create_auth");
lua_pushstring(L, playername.c_str());
lua_pushstring(L, password.c_str());
- PCALL_RES(lua_pcall(L, 2, 0, m_errorhandler));
+ PCALL_RES(lua_pcall(L, 2, 0, error_handler));
+ lua_pop(L, 1); // Pop error handler
}
bool ScriptApiServer::setPassword(const std::string &playername,
@@ -114,6 +118,7 @@ bool ScriptApiServer::setPassword(const std::string &playername,
{
SCRIPTAPI_PRECHECKHEADER
+ int error_handler = PUSH_ERROR_HANDLER(L);
getAuthHandler();
lua_getfield(L, -1, "set_password");
lua_remove(L, -2); // Remove auth handler
@@ -121,7 +126,8 @@ bool ScriptApiServer::setPassword(const std::string &playername,
throw LuaError("Authentication handler missing set_password");
lua_pushstring(L, playername.c_str());
lua_pushstring(L, password.c_str());
- PCALL_RES(lua_pcall(L, 2, 1, m_errorhandler));
+ PCALL_RES(lua_pcall(L, 2, 1, error_handler));
+ lua_remove(L, error_handler);
return lua_toboolean(L, -1);
}