lua-users home
lua-l archive

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


On Thu, Oct 25, 2007 at 07:13:07PM -0500, James Porter wrote:
> Here is the aforementioned patch to extend Lua 5.1.2's 
> exception-handling capabilities. I know Colin in particular expressed 
> interest, though others would probably find it useful as well. It should 
> simplify any C++ code bound to Lua, as well as making lua_call a safer 
> proposition (it throws an exception rather than panicking and exiting). 
> There's more information in the provided README, as well as in my 
> previous message.

AFACIS this patch takes care of the easy part, i.e. lets error be always
thrown as exceptions, but does not take care of the hard part, i.e. make
sure that all necessary cleanup is performed in the wake of an exception.

For example, the Lua state's nCcalls variable surely must be reset before
throwing an exception that is not caught by a Lua protected call...at
least if the lua_State is to be ever used again.

Is calling resetstack() before throwing the exception sufficient?

I.e. that what happens before calling the panic function ... could somebody
with greater understanding of the Lua internals please chime in to say:

- whether it is safe to use a lua_State ever again once that it has called
  its panic function?

(The reference manual does not state anything about the consistency of a 
lua_State after it has called the panic function.)

- if not, which other steps must be taken in addition to resetstack() in
  luaD_throw before throwing an exception (or calling a panic function 
  that throws an exception, but always with the idea of using the Lua
  state again later on).

Regards, Colin