summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/BLua.h2
-rw-r--r--lib/BLua.cc13
2 files changed, 11 insertions, 4 deletions
diff --git a/include/BLua.h b/include/BLua.h
index 4fc9aa0..5d61dc1 100644
--- a/include/BLua.h
+++ b/include/BLua.h
@@ -69,6 +69,7 @@ class Lua : public Base {
Lua();
Lua(const Lua &) throw (GeneralException);
virtual ~Lua();
+ typedef int (*lua_CallWrapper)(lua_State *, lua_CFunction);
void open_base();
void open_table();
void open_io(bool safe = true);
@@ -78,6 +79,7 @@ class Lua : public Base {
void open_dir();
void open_bit();
void open_jit();
+ void setcallwrap(lua_CallWrapper wrapper);
int wrap_open(openlualib_t open) { int n = gettop(); int r = open(L); while (n < gettop()) remove(n);}
void declarefunc(const String &, lua_CFunction, int = LUA_GLOBALSINDEX);
void call(const String &, int = LUA_GLOBALSINDEX, int = 0, int = 0);
diff --git a/lib/BLua.cc b/lib/BLua.cc
index 175f420..e9a3e85 100644
--- a/lib/BLua.cc
+++ b/lib/BLua.cc
@@ -413,10 +413,9 @@ int LuaStatics::print(lua_State * _L) {
int LuaStatics::callwrap(lua_State * __L, lua_CFunction func) {
Lua * L = Lua::find(__L);
- int n;
try {
- n = func(__L);
+ return func(__L);
}
catch (LuaException e) {
L->error(String("LuaException: ") + e.GetMsg());
@@ -425,7 +424,7 @@ int LuaStatics::callwrap(lua_State * __L, lua_CFunction func) {
L->error(String("GeneralException: ") + e.GetMsg());
}
- return n;
+ return 0;
}
int LuaStatics::collector(lua_State * __L) {
@@ -472,10 +471,16 @@ void LuaStatics::destroyhook(lua_State * __L, lua_State * L1) {
delete L;
}
+void Lua::setcallwrap(lua_CallWrapper wrapper) {
+ push((void *) wrapper);
+ luaJIT_setmode(L, -1, LUAJIT_MODE_WRAPCFUNC|LUAJIT_MODE_ON);
+ pop();
+}
+
void Lua::setup_state(lua_State *) {
lualist[L] = this;
lua_atpanic(L, LuaStatics::luapanic);
- lua_setcallwrap(L, LuaStatics::callwrap);
+ setcallwrap(LuaStatics::callwrap);
lua_setcreatehook(L, LuaStatics::createhook);
lua_setdestroyhook(L, LuaStatics::destroyhook);