Force cleanup before longjmp


#1

I want to embed Lua which does longjmp in some API calls.
Is there a handy way to cleanup Rust’s stack and drop local data inside callback method?

I’ve found std::rt::unwind but It’s unstable and I don’t sure that’s safe and relevant.


#2

I think that any attempt to use the Rust unwinding mechanism without actually panicking is bound to be extremely fragile.

You’re probably better off using lua_pcall exclusively, then rewrapping errors into a LuaError object and passing them to panic!, and conversely at Lua -> Rust call points, using catch_panic and translating into Lua errors (optionally unwrapping LuaError). You do lose the stack trace this way, but aside from catch_panic (which is being stabilized), this is all stable and pretty safe.