16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-17 23:39:18 +02:00

fix lua error handling

This commit is contained in:
milek7
2019-02-19 20:29:02 +01:00
parent 01ff1cc217
commit 32e79f7b06
3 changed files with 13 additions and 6 deletions

View File

@@ -1851,8 +1851,12 @@ lua_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) {
// run() subclass details // run() subclass details
void void
lua_event::run_() { lua_event::run_() {
if (lua_func) try {
lua_func(this, m_activator); if (lua_func)
lua_func(this, m_activator);
} catch (...) {
ErrorLog(simulation::Lua.get_error());
}
} }
// export_as_text() subclass details // export_as_text() subclass details

10
lua.cpp
View File

@@ -29,6 +29,11 @@ lua::~lua()
state = nullptr; state = nullptr;
} }
std::string lua::get_error()
{
return std::string(lua_tostring(state, -1));
}
void lua::interpret(std::string file) void lua::interpret(std::string file)
{ {
if (luaL_dofile(state, file.c_str())) { if (luaL_dofile(state, file.c_str())) {
@@ -43,10 +48,7 @@ void lua::interpret(std::string file)
int lua::atpanic(lua_State *s) int lua::atpanic(lua_State *s)
{ {
std::string err(lua_tostring(s, -1)); std::string err(lua_tostring(s, -1));
ErrorLog(std::string(err), logtype::lua); ErrorLog(err, logtype::lua);
#ifdef _WIN32
MessageBox(NULL, err.c_str(), "MaSzyna", MB_OK);
#endif
return 0; return 0;
} }

1
lua.h
View File

@@ -15,6 +15,7 @@ public:
lua(); lua();
~lua(); ~lua();
std::string get_error();
void interpret(std::string file); void interpret(std::string file);
typedef void (*eventhandler_t)(basic_event*, const TDynamicObject*); typedef void (*eventhandler_t)(basic_event*, const TDynamicObject*);