> You can implement a sort of 'lua_break' with hooks and signals; that is how the stand-alone lua interpreter handles Ctrl-C, for instance. (See file 'lua.c' in the main distribuition for details.)
The code has the following remark:
/*
** Function to be called at a C signal. Because a C signal cannot
** just change a Lua state (as there is no proper synchronization),
** this function only sets a hook that, when called, will stop the
** interpreter.
*/
However, lua_sethook is not documented to be free of the need to synchronize. Looking at its code, setting a hook is definitely not a change in a single atomic variable, so I wonder whether calling lua_sethook without synchronization is truly portable
To this day, I have thought that the only correct way to interrupt execution in the Lua VM is by registering a debug hook in advance.
> However, like hooks, that cannot break loops in C code (e.g., library functions).
Yeah, that's why I wrote about the interruption/cancellation extension.