lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello,

what is the overhead of luaJIT_setmode(LUAJIT_MODE_WRAPFUNC)?

Can I call it on every invocation of a certain C function?

My story: I call C++ code from Lua, and it throws C++ exceptions.
Moreover, I set lua_atpanic(L, box_lua_panic) to throw C++
exception as well.

This works very well in my scenario, since my C++ code can call
back Lua code, and vice versa. But in a way, I broke 'pcall' Lua 
built-in. 

Whenever I use it now, and there is an error I get:
false,
"C++ exception"
pair back.

Since I need something more informative than "C++ exception",
I decided the best solution is to re-implement 'pcall' built-in.

One way to re-implement is to turn on WRAPFUNC every time
pcall() is called. Is this a good solution?

An alternative solution would look like: 

int my_pcall(lua_State *L)
{
   try {
              lua_call(L, lua_gettop(L), LUA_MULTRET);
              lua_pushboolean(L, true); /* push completion status */
              lua_insert(L, 1); /* move 'true' to stack start */
   } catch (ClientError *e) {
              lua_settop(L, 0); /* pop any possible garbage */
              lua_pushboolean(L, 0); /* completion status */
              lua_pushstring(L, e->errmsg); /* error message */
   }
   return lua_gettop(L);
}

Any comments on the matter are greatly appreciated,

-- 
Tarantool/Box -- fast, reliable, extensible NoSQL storage
http://tarantool.org
http://github.com/mailru/tarantool