lua-users home
lua-l archive

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


John Passaniti wrote:
> One way to deal with this horror is to not allow control-C during those
> times when it is dangerous-- and dangerous is defined as being "any time
> Lua code is running."

I would say exactly the opposite.  Breaking out of Lua is the safest
place *g*   Restarting at the same place is difficult though.

To break out of Lua just check for example a global var in the main
loop of the virtual machine and if it is set just call a lua error
function.  After each single vm-instruction the system is in a stable
state an may be aborted by the Lua error handling routines.
But beware: Lua is in a save state.  The semantics of your application
program may be totally broken.

Catching a Ctrl-C in a C function called by Lua is a little bit more
difficult.  You have to do it by hand (you may check the same global
the vm-loop is checking).  And, if you're sure your C-function is at
a point where it is legal to abort you may call lua_error & co.

Ciao, ET.