Unfortunately, there's nothing sol2 can do about `longjmp`. Unless I were to take over malloc for the duration of any user-supplied functions to ensure memory safety (but no execution safety: for example, typical handle resource cleanup), there's no way for me to prevent it from happening. If you build Lua as C++, you can call `luaL_error()` and -- as mentioned before -- Lua will trigger stack unwinding. LuaJIT also has made significant strides in allowing stack unwinding on all platforms (including x86) in LuaJIT-2.1.0-beta3.
There's really no getting around longjmp. The best thing you can do is use as many safety features as humanly possible to prevent resource-critical code from exploding. In sol2, that's sol::optional<type> and sol::protected_function. Also see `SOL_CHECK_ARGUMENTS` and all the safety macros defined here:
http://sol2.readthedocs.io/en/latest/safety.html#configIt's not ideal, but it's the best I can do. I can only hope it helps...!