lua-users home
lua-l archive

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


I use luajit 2.0 beta6, and I write a program like this:

jmb_buf buffer;

int DoFunc(lua_State* p)
{
if(!setjmp(buffer))
{
try
{
luaL_error(p, "error");
//throw "error";      //if I use throw, the program works fine
}
catch(...)
{
longjmp(buffer, 1);
}
}
else
{
printf("LongJmp\n");
}
}

int main()
{
lua_State* p = luaL_newstate();
DoFunc(p);
DoFunc(p);   //abort 
lua_close(p);
return 0;
}

If I use lua_error to throw a exception, the program will abort when second call DoFunc.The output is

LongJmp
terminate called without an active exception
aborted

But when I use throw instead, all works fine. My linux version is 2.6.18-164.el5 x86_64

I know that longjmp will jump the stack, maybe use lua_error and longjmp destroy something in luajit and then use lua_error again cause abort?
In the luajit extensions, it said "Throwing Lua errors across C++ frames is safe", maybe can't be used with longjmp at same time?