lua-users home
lua-l archive

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

On Mon, Jan 10, 2011 at 4:21 PM, Drake Wilson <> wrote:
> Quoth Julio Merino <>, on 2011-01-10 15:50:45 +0000:
>> [...]
>> void safe_gettable(lua_State* s, const int index)
>> {
>>     if (setjmp(buf) == 0)
>>         lua_gettable(s, index);
>>     else
>>         throw error('Uh oh, lua_gettable failed');
>> }
> This doesn't answer your original question, but lua_atpanic isn't for
> that.  The above fails if safe_gettable is ever called inside a pcall.
> The error will be propagated immediately to the site of the pcall, and
> the panic handler does not run.  Further, your stack has already been
> unwound, and depending on the platform, destructors may not get called
> and such.  Essentially this is the "stock Lua doesn't play well with
> C++ unwinding" bit.  (Unfortunately, I don't immediately recall a good
> solution that works in your case; perhaps someone else does.)

Ah, very true -- had missed that.  Well, I guess this indirectly
answers my question too.

What I'm currently doing[1] is to wrap the unsafe call in a tiny C
function of its own and then call it explicitly with lua_pcall.
(Unfortunately, that has overhead and can still fail due to
out-of-memory errors because the lua_push* functions required for such
setup are not protected...)

1: See the lua::state::get_table method (line 154) in

Julio Merino