summaryrefslogtreecommitdiff
path: root/src/script/common/c_internal.cpp
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2013-12-18 16:35:55 -0500
committerShadowNinja <shadowninja@minetest.net>2013-12-18 16:35:55 -0500
commit49cec3f78240ed6310a9b5dd05ce09a79ed5a12e (patch)
tree38e8199e49906357939e74b6ed0b00f6f54de976 /src/script/common/c_internal.cpp
parent38d112033b3ba0ea0360fced334a279576aafc5d (diff)
downloadminetest-49cec3f78240ed6310a9b5dd05ce09a79ed5a12e.tar.gz
minetest-49cec3f78240ed6310a9b5dd05ce09a79ed5a12e.tar.bz2
minetest-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.cpp12
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);