From db4ea4658c58772ee447ff0eff8bb39b692081ec Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Tue, 15 Apr 2014 13:30:46 -0400 Subject: Only push the Lua error handler once --- src/script/cpp_api/s_base.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src/script/cpp_api/s_base.cpp') diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp index 932cc5015..774b3f51d 100644 --- a/src/script/cpp_api/s_base.cpp +++ b/src/script/cpp_api/s_base.cpp @@ -72,6 +72,10 @@ ScriptApiBase::ScriptApiBase() m_luastack = luaL_newstate(); assert(m_luastack); + // Add and save an error handler + lua_pushcfunction(m_luastack, script_error_handler); + m_errorhandler = lua_gettop(m_luastack); + // Make the ScriptApiBase* accessible to ModApiBase lua_pushlightuserdata(m_luastack, this); lua_setfield(m_luastack, LUA_REGISTRYINDEX, "scriptapi"); @@ -125,23 +129,18 @@ bool ScriptApiBase::loadScript(const std::string &scriptpath) lua_State *L = getStack(); - lua_pushcfunction(L, script_error_handler); - int errorhandler = lua_gettop(L); - - int ret = luaL_loadfile(L, scriptpath.c_str()) || lua_pcall(L, 0, 0, errorhandler); - if(ret){ - errorstream<<"========== ERROR FROM LUA ==========="<