[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Why is the stack cleared on panic?
- From: Drake Wilson <drake@...>
- Date: Mon, 10 Jan 2011 09:21:12 -0700
Quoth Julio Merino <email@example.com>, on 2011-01-10 15:50:45 +0000:
> static jmp_buf buf;
> int panic_handler(lua_State* s)
> longjmp(buf, 1);
> ... some init function here that calls lua_atpanic(s, panic_handler) ...
> void safe_gettable(lua_State* s, const int index)
> if (setjmp(buf) == 0)
> lua_gettable(s, index);
> 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.)
---> Drake Wilson