diff --git a/Event.cpp b/Event.cpp index 58d4f790..37ad4af4 100644 --- a/Event.cpp +++ b/Event.cpp @@ -1851,8 +1851,12 @@ lua_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) { // run() subclass details void lua_event::run_() { - if (lua_func) - lua_func(this, m_activator); + try { + if (lua_func) + lua_func(this, m_activator); + } catch (...) { + ErrorLog(simulation::Lua.get_error()); + } } // export_as_text() subclass details diff --git a/lua.cpp b/lua.cpp index a6ad04fd..9f76fd62 100644 --- a/lua.cpp +++ b/lua.cpp @@ -29,6 +29,11 @@ lua::~lua() state = nullptr; } +std::string lua::get_error() +{ + return std::string(lua_tostring(state, -1)); +} + void lua::interpret(std::string file) { if (luaL_dofile(state, file.c_str())) { @@ -43,10 +48,7 @@ void lua::interpret(std::string file) int lua::atpanic(lua_State *s) { std::string err(lua_tostring(s, -1)); - ErrorLog(std::string(err), logtype::lua); -#ifdef _WIN32 - MessageBox(NULL, err.c_str(), "MaSzyna", MB_OK); -#endif + ErrorLog(err, logtype::lua); return 0; } diff --git a/lua.h b/lua.h index 3a5f76d8..0e781279 100644 --- a/lua.h +++ b/lua.h @@ -15,6 +15,7 @@ public: lua(); ~lua(); + std::string get_error(); void interpret(std::string file); typedef void (*eventhandler_t)(basic_event*, const TDynamicObject*);