Description
Currently, rlua makes sure to only call Lua API functions that can cause an error from within error_guard
, which uses lua_pcall
to run a Rust closure in a protected environment. This causes all Lua errors to be caught by lua_pcall
.
Since Lua's error handling uses setjmp
and longjmp
to do non-local control flow, an error will longjmp
to the lua_pcall
, skipping across the Rust closure passed to error_guard
. According to IRC this is undefined behaviour in Rust. EDIT: People are also claiming that it's unsafe in this user forum thread.
Fixing this is hard. It would require that all uses of lua_pcall
only call C functions. And calling lua_error
from Rust would never be a safe thing to do, since it must skip across a Rust stack frame.
If this is really UB, the only way to write a safe Lua wrapper would involve writing C code. Not sure if that's really the case, though...