From e36edf4ae6a2b908f8fc3bf4c9f734baa835bf08 Mon Sep 17 00:00:00 2001 From: ShokerStlk Date: Sun, 19 Feb 2017 23:04:55 +0300 Subject: [PATCH] Break code moved back to raii_guard() --- src/xrScriptEngine/script_engine.cpp | 26 +++++++++++++++----------- src/xrScriptEngine/script_engine.hpp | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/xrScriptEngine/script_engine.cpp b/src/xrScriptEngine/script_engine.cpp index 4435de970ab..e0589b20392 100644 --- a/src/xrScriptEngine/script_engine.cpp +++ b/src/xrScriptEngine/script_engine.cpp @@ -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); @@ -563,6 +563,12 @@ bool CScriptEngine::print_output(lua_State* L, LPCSTR caScriptFileName, int erro } #endif } + + if (caErrorText != NULL) + { + S = caErrorText; + } + return true; } @@ -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 diff --git a/src/xrScriptEngine/script_engine.hpp b/src/xrScriptEngine/script_engine.hpp index 86b00a3f6d2..2e450d7a921 100644 --- a/src/xrScriptEngine/script_engine.hpp +++ b/src/xrScriptEngine/script_engine.hpp @@ -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);