Skip to content

Commit e36edf4

Browse files
committed
Break code moved back to raii_guard()
1 parent 1885aa9 commit e36edf4

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/xrScriptEngine/script_engine.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ struct raii_guard : private Noncopyable
534534
}
535535
};
536536

537-
bool CScriptEngine::print_output(lua_State* L, LPCSTR caScriptFileName, int errorCode)
537+
bool CScriptEngine::print_output(lua_State* L, LPCSTR caScriptFileName, int errorCode, const char* caErrorText)
538538
{
539539
CScriptEngine* scriptEngine = GetInstance(L);
540540
VERIFY(scriptEngine);
@@ -563,6 +563,12 @@ bool CScriptEngine::print_output(lua_State* L, LPCSTR caScriptFileName, int erro
563563
}
564564
#endif
565565
}
566+
567+
if (caErrorText != NULL)
568+
{
569+
S = caErrorText;
570+
}
571+
566572
return true;
567573
}
568574

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

754760
int CScriptEngine::lua_pcall_failed(lua_State* L)
755761
{
756-
#if (!defined(DEBUG) && !XRAY_EXCEPTIONS)
757-
print_output(L, "", 0); // Force game to not break in raii_guard() for this type of errors
758-
#else
759-
print_output(L, "", LUA_ERRRUN); // Default behavior
760-
#endif
761-
762-
on_error(L);
762+
const char* sErrorText = NULL;
763763

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

771+
print_output(L, "", LUA_ERRRUN, sErrorText);
772+
on_error(L);
773+
770774
#if !XRAY_EXCEPTIONS
771775
xrDebug::Fatal(DEBUG_INFO, "LUA error: %s", lua_isstring(L, -1) ? lua_tostring(L, -1) : "");
772776
#endif

src/xrScriptEngine/script_engine.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class XRSCRIPTENGINE_API CScriptEngine
136136
luabind::object name_space(LPCSTR namespace_name);
137137
int error_log(LPCSTR caFormat, ...);
138138
int script_log(LuaMessageType message, LPCSTR caFormat, ...);
139-
static bool print_output(lua_State* L, LPCSTR caScriptName, int iErrorCode = 0);
139+
static bool print_output(lua_State* L, LPCSTR caScriptName, int iErrorCode = 0, const char* caErrorText = NULL);
140140

141141
private:
142142
static void print_error(lua_State* L, int iErrorCode);

0 commit comments

Comments
 (0)