diff options
author | ShadowNinja <shadowninja@minetest.net> | 2013-12-18 16:35:55 -0500 |
---|---|---|
committer | ShadowNinja <shadowninja@minetest.net> | 2013-12-18 16:35:55 -0500 |
commit | 49cec3f78240ed6310a9b5dd05ce09a79ed5a12e (patch) | |
tree | 38e8199e49906357939e74b6ed0b00f6f54de976 /src/script/common/c_internal.cpp | |
parent | 38d112033b3ba0ea0360fced334a279576aafc5d (diff) | |
download | hax-minetest-server-49cec3f78240ed6310a9b5dd05ce09a79ed5a12e.tar.gz hax-minetest-server-49cec3f78240ed6310a9b5dd05ce09a79ed5a12e.zip |
Handle LuaErrors in Lua -> C++ calls on LuaJIT
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); |