Skip to content

Commit

Permalink
Break code moved back to raii_guard()
Browse files Browse the repository at this point in the history
  • Loading branch information
ShokerStlk committed Feb 19, 2017
1 parent 1885aa9 commit e36edf4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
26 changes: 15 additions & 11 deletions src/xrScriptEngine/script_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ struct raii_guard : private Noncopyable
}
};

bool CScriptEngine::print_output(lua_State* L, LPCSTR caScriptFileName, int errorCode)
bool CScriptEngine::print_output(lua_State* L, LPCSTR caScriptFileName, int errorCode, const char* caErrorText)
{
CScriptEngine* scriptEngine = GetInstance(L);
VERIFY(scriptEngine);
Expand Down Expand Up @@ -563,6 +563,12 @@ bool CScriptEngine::print_output(lua_State* L, LPCSTR caScriptFileName, int erro
}
#endif
}

if (caErrorText != NULL)
{
S = caErrorText;
}

return true;
}

Expand Down Expand Up @@ -753,20 +759,18 @@ void CScriptEngine::lua_error(lua_State* L)

int CScriptEngine::lua_pcall_failed(lua_State* L)
{
#if (!defined(DEBUG) && !XRAY_EXCEPTIONS)
print_output(L, "", 0); // Force game to not break in raii_guard() for this type of errors
#else
print_output(L, "", LUA_ERRRUN); // Default behavior
#endif

on_error(L);
const char* sErrorText = NULL;

#ifndef DEBUG // Debug already do it
// Print Lua call stack
const char* lua_error_text = lua_tostring(L, 1); // error text
luaL_traceback(L, L, make_string("%s\n", lua_error_text).c_str(), 1); // add stack trace to it
const char* lua_error_text = lua_tostring(L, -1); // lua-error text
luaL_traceback(L, L, make_string("[LUA][Error]: %s\n", lua_error_text).c_str(), 1); // add lua traceback to it
sErrorText = lua_tostring(L, -1); // get combined error text from lua stack
lua_pop(L, 1); // restore lua stack
#endif

print_output(L, "", LUA_ERRRUN, sErrorText);
on_error(L);

#if !XRAY_EXCEPTIONS
xrDebug::Fatal(DEBUG_INFO, "LUA error: %s", lua_isstring(L, -1) ? lua_tostring(L, -1) : "");
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/xrScriptEngine/script_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class XRSCRIPTENGINE_API CScriptEngine
luabind::object name_space(LPCSTR namespace_name);
int error_log(LPCSTR caFormat, ...);
int script_log(LuaMessageType message, LPCSTR caFormat, ...);
static bool print_output(lua_State* L, LPCSTR caScriptName, int iErrorCode = 0);
static bool print_output(lua_State* L, LPCSTR caScriptName, int iErrorCode = 0, const char* caErrorText = NULL);

private:
static void print_error(lua_State* L, int iErrorCode);
Expand Down

0 comments on commit e36edf4

Please sign in to comment.