From 870dce603bd09fe9b57b12a59ae2deb510550d6c Mon Sep 17 00:00:00 2001 From: Pavel Dolgov Date: Wed, 17 Aug 2016 15:41:06 +0300 Subject: [PATCH] Split wrap into two static functions Fix segfault: close #42 --- src/luawt/globals.hpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/luawt/globals.hpp b/src/luawt/globals.hpp index c211a0d..a585a83 100644 --- a/src/luawt/globals.hpp +++ b/src/luawt/globals.hpp @@ -215,15 +215,24 @@ inline void luawt_toLua(lua_State* L, template struct wrap { - static int func(lua_State* L) { + static int internalFunc(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 = internalFunc(L); + if (result == -1) { + return lua_error(L); } - return lua_error(L); + return result; } };