lua-users home
lua-l archive

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


>
> It should be enough to just push the error message as part of LUAI_TRY.
> With C++ it would be something like:
>
> #define LUAI_TRY(L,c,a) try { a } \
>      catch(std::exception e) \
>          { lua_pushstring(L, e.what()); (c)->status = -1; } \
>      catch(...) \
>          { if ((c)->status == 0) (c)->status = -1; }
>
> --
> - tom
> telliamed@whoopdedo.org

Thanks for responding! I was having trouble with lua_pushstring not
doing anything for me. I think I finally figured out why.

I needed to change the status code from -1 to either LUA_ERRSYNTAX or
LUA_ERRRUN. Otherwise the string was getting lost. I found those two
cases in luaD_seterrorobj where the comment suggests it expects the
error message on the top.


void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) {
  switch (errcode) {
    case LUA_ERRMEM: {
      setsvalue2s(L, oldtop, luaS_newliteral(L, MEMERRMSG));
      break;
    }
    case LUA_ERRERR: {
      setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling"));
      break;
    }
    case LUA_ERRSYNTAX:
    case LUA_ERRRUN: {
      setobjs2s(L, oldtop, L->top - 1);  /* error message on current top */
      break;
    }
  }
  L->top = oldtop + 1;
}



Anyway, I think it's all working now I hope. I'll probably look at
posting my changes somewhere once I clean things up. I wish this was a
simple macro change, but I really needed to push these down into
functions to hide the implementation details from everything else and
avoid name clashes with stuff in Apple's Foundation headers. This also
required a slight signature change so I could invoke the Pfunc with
userdata inside my function.

But the nice things are that I can compile Lua as normal C (as usual),
and only need to compile one extra file as Obj-C so anything using Lua
is unaffected/sheltered from the Obj-C dependency. Another interesting
side effect is that this should also catch C++ exceptions without
actually having to compile Lua as C++.


Thanks,
Eric
-- 
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/