lua-users home
lua-l archive

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

Em 07/12/2011 12:37, Patrick Rapin escreveu:
The library function luaL_checkstring, like all luaL_check* series,
return a valid value if the type is the expected one, or signals an
error when the type is not correct.
If you have compiled Lua in C++ mode without defining LUA_USE_LONGJMP,
Lua uses C++ exceptions for its errors. In this case, what you see if
perfectly normal.
Hi Patrick, thanks for your reply.

I tested the snippet given in the previous e-mail with and without the define LUA_USE_LONGJMP.
In both cases it ended up in a system exception, so I started to delve into Lua src.

What is happening is that luaD_throw() is reaching the abort() because I have no
error handler.

I have used  lua_atpanic () to setup a panic function,but abort is always called anyway (see code below) !
I expected that if the panic function handled the situation, abort should **not** be called.
In order for the panic function to avoid abort() is it supposed to always do a longjump ?

The function luaD_throw mentions a  "thread error handler", how do I set that up  ?

l_noret luaD_throw (lua_State *L, int errcode) {
  if (L->errorJmp) {  /* thread has an error handler? */
    L->errorJmp->status = errcode;  /* set status */
    LUAI_THROW(L, L->errorJmp);  /* jump to it */
  else {  /* thread has no error handler */
    L->status = cast_byte(errcode);  /* mark it as dead */
    if (G(L)->mainthread->errorJmp) {  /* main thread has a handler? */
      setobjs2s(L, G(L)->mainthread->top++, L->top - 1);  /* copy error obj. */
      luaD_throw(G(L)->mainthread, errcode);  /* re-throw in main thread */
    else {  /* no handler at all; abort */
      if (G(L)->panic) {  /* panic function? */
        G(L)->panic(L);  /* call it (last chance to jump out) */

best regards,
Rod Senra