diff --git a/src/npge/cpp/lua_npge.cpp b/src/npge/cpp/lua_npge.cpp index 9505e85..a705364 100644 --- a/src/npge/cpp/lua_npge.cpp +++ b/src/npge/cpp/lua_npge.cpp @@ -20,15 +20,24 @@ using namespace lnpge; template struct wrap { - static int func(lua_State* L) { + static int func0(lua_State* L) { try { return F(L); } catch (std::exception& e) { lua_pushstring(L, e.what()); + return -1; } catch (...) { lua_pushliteral(L, "Unknown exception"); + return -1; + } + } + + static int func(lua_State* L) { + int result = func0(L); + if (result == -1) { + return lua_error(L); } - return lua_error(L); + return result; } };