aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api/s_base.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/cpp_api/s_base.cpp')
-rw-r--r--src/script/cpp_api/s_base.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp
index b957dc64f..898271743 100644
--- a/src/script/cpp_api/s_base.cpp
+++ b/src/script/cpp_api/s_base.cpp
@@ -29,6 +29,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
extern "C" {
#include "lualib.h"
+#if USE_LUAJIT
+ #include "luajit.h"
+#endif
}
#include <stdio.h>
@@ -73,6 +76,14 @@ ScriptApiBase::ScriptApiBase()
lua_pushlightuserdata(m_luastack, this);
lua_setfield(m_luastack, LUA_REGISTRYINDEX, "scriptapi");
+ // If we are using LuaJIT add a C++ wrapper function to catch
+ // exceptions thrown in Lua -> C++ calls
+#if USE_LUAJIT
+ lua_pushlightuserdata(m_luastack, (void*) script_exception_wrapper);
+ luaJIT_setmode(m_luastack, -1, LUAJIT_MODE_WRAPCFUNC | LUAJIT_MODE_ON);
+ lua_pop(m_luastack, 1);
+#endif
+
m_server = 0;
m_environment = 0;
m_guiengine = 0;