While all this conversation about the C-part is really interesting, my original concern was using plain Lua.
Without a way of specifying/altering the traceback when raising an error, the "error recuperation + cleanup + bubbling up" strategy means either losing the traceback information or altering the error significantly (i.e. changing it to a table, and adding a traceback field inside it)
I'm sure this problem can be solved by using C, but I'd be much more interested in finding a plain Lua solution, if possible.
The best I could do was proposing adding a second parameter to error: error(msg, traceback) <- traceback replaces or is chained to the error traceback.
What are your thoughts on that?
Thanks a lot,