Handle a lua error thrown in a protected function by printing the traceback and bubbling exception up to caller. Lua errors are generally unrecoverable, so this exception should not be caught but instead should terminate the process. The point of having this error handler rather than just using unprotected Lua functions which terminate the process automatically is that this function provides more
| 94 | // than just using unprotected Lua functions which terminate the process automatically is that this |
| 95 | // function provides more useful error messages including Lua tracebacks and line numbers. |
| 96 | void handle_lua_error(const sol::protected_function_result &luares) |
| 97 | { |
| 98 | sol::error luaerr = luares; |
| 99 | const auto msg = luaerr.what(); |
| 100 | if (msg != nullptr) |
| 101 | { |
| 102 | // util::Log is thread-safe |
| 103 | util::UnbufferedLog(logERROR) << msg << "\n"; |
| 104 | } |
| 105 | else |
| 106 | { |
| 107 | util::UnbufferedLog(logERROR) << "unknown error\n"; |
| 108 | } |
| 109 | throw util::exception("Lua error (see stderr for traceback)"); |
| 110 | } |
| 111 | |
| 112 | Sol2ScriptingEnvironment::Sol2ScriptingEnvironment( |
| 113 | const std::string &file_name, |
no test coverage detected