diff options
Diffstat (limited to 'src/script/common/c_internal.cpp')
-rw-r--r-- | src/script/common/c_internal.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/script/common/c_internal.cpp b/src/script/common/c_internal.cpp index 2866cfe86..90846676f 100644 --- a/src/script/common/c_internal.cpp +++ b/src/script/common/c_internal.cpp @@ -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); |