lua-users home
lua-l archive

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


On 04/03/2012 05:58 PM, Eric Wing wrote:
I want to use Objective-C's exception handling mechanism with Lua. It
is very similar to C++'s exception handling mechanism (and in fact
they are unified behind the scenes with Apple's modern runtime).

I modified luaconf.h and ldo.c  (Lua 5.1) and this seems to work
pretty well and catches both Lua and Obj-C errors which is what I
think I want .

But in the case of an exception originating from Obj-C (not Lua), I
would like to set the Lua error message to pass the Obj-C exception
description (string) pcall returns this error string. How do I set the
Lua error string while inside LUAI_TRY (catch block)?


Thanks,
Eric

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