@@ -505,13 +505,12 @@ struct raii_guard : private Noncopyable
505505{
506506 CScriptEngine* scriptEngine;
507507 int m_error_code;
508- const char * m_error_description;
508+ const char *& m_error_description;
509509
510- raii_guard (CScriptEngine* scriptEngine, int error_code, const char * error_description)
510+ raii_guard (CScriptEngine* scriptEngine, int error_code, const char *& error_description)
511+ :m_error_code(error_code), m_error_description(error_description)
511512 {
512513 this ->scriptEngine = scriptEngine;
513- m_error_code = error_code;
514- m_error_description = error_description;
515514 }
516515
517516 ~raii_guard ()
@@ -524,9 +523,9 @@ struct raii_guard : private Noncopyable
524523#ifdef DEBUG
525524 static const bool break_on_assert = !!strstr (Core.Params , " -break_on_assert" );
526525#else
527- static const bool break_on_assert = true ;
526+ static const bool break_on_assert = true ; // xxx: there is no point to set it true\false in Release, since game will crash anyway in most cases due to XRAY_EXCEPTIONS disabled in Release build.
528527#endif
529- if (!m_error_code) return ;
528+ if (!m_error_code) return ; // Check "lua_pcall_failed" before changing this!
530529 if (break_on_assert)
531530 R_ASSERT2 (!m_error_code, m_error_description);
532531 else
@@ -535,7 +534,7 @@ struct raii_guard : private Noncopyable
535534 }
536535};
537536
538- 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 )
539538{
540539 CScriptEngine* scriptEngine = GetInstance (L);
541540 VERIFY (scriptEngine);
@@ -564,6 +563,12 @@ bool CScriptEngine::print_output(lua_State* L, LPCSTR caScriptFileName, int erro
564563 }
565564#endif
566565 }
566+
567+ if (caErrorText != NULL )
568+ {
569+ S = caErrorText;
570+ }
571+
567572 return true ;
568573}
569574
@@ -754,8 +759,18 @@ void CScriptEngine::lua_error(lua_State* L)
754759
755760int CScriptEngine::lua_pcall_failed (lua_State* L)
756761{
757- print_output (L, " " , LUA_ERRRUN);
762+ const char * sErrorText = NULL ;
763+
764+ #ifndef DEBUG // Debug already do 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
769+ #endif
770+
771+ print_output (L, " " , LUA_ERRRUN, sErrorText );
758772 on_error (L);
773+
759774#if !XRAY_EXCEPTIONS
760775 xrDebug::Fatal (DEBUG_INFO, " LUA error: %s" , lua_isstring (L, -1 ) ? lua_tostring (L, -1 ) : " " );
761776#endif
@@ -786,9 +801,8 @@ void CScriptEngine::setup_callbacks()
786801#if !XRAY_EXCEPTIONS
787802 luabind::set_error_callback (CScriptEngine::lua_error);
788803#endif
789- # ifndef MASTER_GOLD
804+
790805 luabind::set_pcall_callback ([](lua_State* L) { lua_pushcfunction (L, CScriptEngine::lua_pcall_failed); });
791- #endif
792806 }
793807#if !XRAY_EXCEPTIONS
794808 luabind::set_cast_failed_callback (CScriptEngine::lua_cast_failed);
0 commit comments