From 378d30834bee11404b75c2934c4ec55e05c934f5 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 28 Oct 2017 01:44:02 +0300 Subject: [PATCH] [Server] Add special error handler for Sol back in, but only for Windows --- apps/openmw-mp/Script/LuaState.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/apps/openmw-mp/Script/LuaState.cpp b/apps/openmw-mp/Script/LuaState.cpp index cf8c81c86..5cf2bbcc2 100644 --- a/apps/openmw-mp/Script/LuaState.cpp +++ b/apps/openmw-mp/Script/LuaState.cpp @@ -80,6 +80,17 @@ LuaState::LuaState() configEnv = sol::environment(*lua, sol::create, lua->globals()); lua->set("Config", configEnv); // plain global environment for mod configuration + // Enable a special Sol error handler for Windows, because exceptions aren't caught properly + // in main.cpp for it +#if defined(SOL_SAFE_FUNCTIONS) && defined(WIN32) + lua->set_function("ErrorHandler", [](sol::object error_msg) { + LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, ("Lua: " + error_msg.as()).c_str()); + }); + + sol::reference errHandler = (*lua)["ErrorHandler"]; + sol::protected_function::set_default_handler(errHandler); +#endif + sol::table Constants = lua->create_named_table("Constants"); Constants.set_function("getAttributeCount", []() {