@@ -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
754760int 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
0 commit comments