Skip to content

Commit

Permalink
Split wrap into two static functions
Browse files Browse the repository at this point in the history
Fix segfault: close LuaAndC#42
  • Loading branch information
zer0main committed Aug 17, 2016
1 parent 09a956c commit 870dce6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/luawt/globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,24 @@ inline void luawt_toLua<luawt_Application>(lua_State* L,

template<lua_CFunction F>
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;
}
};

Expand Down

0 comments on commit 870dce6

Please sign in to comment.