[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: error, setjmp and exceptions
- From: Mark Hamburg <mhamburg@...>
- Date: Fri, 02 Jan 2004 10:57:09 -0800
Throwing the Lua state is a little interesting as a choice but I guess it
doesn't cause any problems.
Please make it possible to separately define L_THROW and L_TRY as well
though I suspect that in order to do exception translation I will probably
still end up overriding luaD_throw and luaD_rawrunprotected.
Thanks.
Mark
on 12/18/03 11:57 AM, Roberto Ierusalimschy at roberto@inf.puc-rio.br wrote:
>> The vector's destructor never gets called and its memory is leaked.
>
> If you compile Lua as C++ code, it is not difficult to change it
> to use real exceptions instead of setjmp/longjmp. Lua 5.1 will have
> a compilation flag for that. I hope the next lines give the
> general idea:
>
>> #ifndef LUA_USEEXCEPTIONS
>>
>> #define L_THROW(c) longjmp((c)->b, 1)
>> #define L_TRY(c,a) if (setjmp((c)->b) == 0) { a }
>>
>> #else
>>
>> #define L_THROW(c) throw(c)
>> #define L_TRY(c,a) try { a } catch(...) \
>> { if ((c)->status == 0) (c)->status = -1; }
>>
>> #endif
>
> This is not a perfect solution (other C++ exceptions are also catched
> by Lua protected calls), but it seems to work ok.
>
> -- Roberto
>