1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-13 08:35:20 +02:00

Handle LuaErrors in Lua -> C++ calls on LuaJIT

This commit is contained in:
ShadowNinja
2013-12-18 16:35:55 -05:00
parent 38d112033b
commit 49cec3f782
18 changed files with 113 additions and 134 deletions

View File

@@ -55,6 +55,18 @@ int script_error_handler(lua_State *L) {
return 1;
}
int script_exception_wrapper(lua_State *L, lua_CFunction f)
{
try {
return f(L); // Call wrapped function and return result.
} catch (const char *s) { // Catch and convert exceptions.
lua_pushstring(L, s);
} catch (LuaError& e) {
lua_pushstring(L, e.what());
}
return lua_error(L); // Rethrow as a Lua error.
}
void script_error(lua_State *L)
{
const char *s = lua_tostring(L, -1);