| 47 | // std::current_exception and wrap it in a e_lua_exception object. |
| 48 | template <int (*F)( lua_State * L )> |
| 49 | int wrap_lua_CFunction( lua_State * L ) noexcept |
| 50 | { |
| 51 | return leaf::try_catch( |
| 52 | [&] |
| 53 | { |
| 54 | return F(L); |
| 55 | }, |
| 56 | [&]( leaf::error_info const & ei ) |
| 57 | { |
| 58 | ei.error().load( e_lua_exception{std::current_exception()} ); |
| 59 | return luaL_error(L, "C++ Exception"); // luaL_error does not return (longjmp). |
| 60 | } ); |
| 61 | } |
| 62 | |
| 63 | |
| 64 | // This is a C callback with a specific signature, callable from programs |