From 2d31d84070cff34051026cf0f9622087669002bb Mon Sep 17 00:00:00 2001 From: ThePhD Date: Sat, 11 Nov 2017 07:42:14 -0500 Subject: [PATCH] attempt to wrangle exception handling on multiple systems --- single/sol/sol.hpp | 34 +++++++++++++++++++++------------- sol/protected_function.hpp | 17 +++++++++++------ sol/types.hpp | 13 ++++++++----- 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index 090a47e8..36332571 100644 --- a/single/sol/sol.hpp +++ b/single/sol/sol.hpp @@ -20,8 +20,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. -// Generated 2017-11-09 22:36:14.826447 UTC -// This header was generated with sol v2.18.6 (revision 90bbead) +// Generated 2017-11-11 12:41:27.450855 UTC +// This header was generated with sol v2.18.6 (revision e667e69) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -4408,13 +4408,16 @@ namespace sol { try { return f(L); } - catch (const char* s) { - lua_pushstring(L, s); + catch (const char* cs) { + lua_pushstring(L, cs); + } + catch (const std::string& s) { + lua_pushlstring(L, s.c_str(), s.size()); } catch (const std::exception& e) { lua_pushstring(L, e.what()); } -#if defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && defined(SOL_LUAJIT) +#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) // LuaJIT cannot have the catchall when the safe propagation is on // but LuaJIT will swallow all C++ errors // if we don't at least catch std::exception ones @@ -4423,7 +4426,7 @@ namespace sol { } #endif // LuaJIT cannot have the catchall, but we must catch std::exceps for it return lua_error(L); -#endif +#endif // Safe exceptions } #ifdef SOL_NOEXCEPT_FUNCTION_TYPE @@ -4465,7 +4468,7 @@ namespace sol { catch (const std::exception& e) { lua_pushstring(L, e.what()); } -#if defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && !defined(SOL_LUAJIT) +#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) // LuaJIT cannot have the catchall when the safe propagation is on // but LuaJIT will swallow all C++ errors // if we don't at least catch std::exception ones @@ -13543,16 +13546,16 @@ namespace sol { stack::push(lua_state(), error); } }; -#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) || defined(SOL_LUAJIT) +#if defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && !defined(SOL_LUAJIT) try { -#endif +#endif // Safe Exception Propagation #endif // No Exceptions firstreturn = (std::max)(1, static_cast(stacksize - n - static_cast(h.valid()))); code = luacall(n, LUA_MULTRET, h); poststacksize = lua_gettop(lua_state()) - static_cast(h.valid()); returncount = poststacksize - (firstreturn - 1); #ifndef SOL_NO_EXCEPTIONS -#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) || defined(SOL_LUAJIT) +#if defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && !defined(SOL_LUAJIT) } // Handle C++ errors thrown from C++ functions bound inside of lua catch (const char* error) { @@ -13560,12 +13563,17 @@ namespace sol { firstreturn = lua_gettop(lua_state()); return protected_function_result(lua_state(), firstreturn, 0, 1, call_status::runtime); } + catch (const std::string& error) { + onexcept(error.c_str()); + firstreturn = lua_gettop(lua_state()); + return protected_function_result(lua_state(), firstreturn, 0, 1, call_status::runtime); + } catch (const std::exception& error) { onexcept(error.what()); firstreturn = lua_gettop(lua_state()); return protected_function_result(lua_state(), firstreturn, 0, 1, call_status::runtime); } -#if !defined(SOL_LUAJIT) +#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) // LuaJIT cannot have the catchall when the safe propagation is on // but LuaJIT will swallow all C++ errors // if we don't at least catch std::exception ones @@ -13577,8 +13585,8 @@ namespace sol { #endif // LuaJIT #else // do not handle exceptions: they can be propogated into C++ and keep all type information / rich information -#endif // about as safe as possible -#endif // No Exceptions +#endif // Safe Exception Propagation +#endif // Exceptions vs. No Exceptions return protected_function_result(lua_state(), firstreturn, returncount, returncount, code); } diff --git a/sol/protected_function.hpp b/sol/protected_function.hpp index 04d272d5..4525d5d8 100644 --- a/sol/protected_function.hpp +++ b/sol/protected_function.hpp @@ -150,16 +150,16 @@ namespace sol { stack::push(lua_state(), error); } }; -#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) || defined(SOL_LUAJIT) +#if defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && !defined(SOL_LUAJIT) try { -#endif +#endif // Safe Exception Propagation #endif // No Exceptions firstreturn = (std::max)(1, static_cast(stacksize - n - static_cast(h.valid()))); code = luacall(n, LUA_MULTRET, h); poststacksize = lua_gettop(lua_state()) - static_cast(h.valid()); returncount = poststacksize - (firstreturn - 1); #ifndef SOL_NO_EXCEPTIONS -#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) || defined(SOL_LUAJIT) +#if defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && !defined(SOL_LUAJIT) } // Handle C++ errors thrown from C++ functions bound inside of lua catch (const char* error) { @@ -167,12 +167,17 @@ namespace sol { firstreturn = lua_gettop(lua_state()); return protected_function_result(lua_state(), firstreturn, 0, 1, call_status::runtime); } + catch (const std::string& error) { + onexcept(error.c_str()); + firstreturn = lua_gettop(lua_state()); + return protected_function_result(lua_state(), firstreturn, 0, 1, call_status::runtime); + } catch (const std::exception& error) { onexcept(error.what()); firstreturn = lua_gettop(lua_state()); return protected_function_result(lua_state(), firstreturn, 0, 1, call_status::runtime); } -#if !defined(SOL_LUAJIT) +#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) // LuaJIT cannot have the catchall when the safe propagation is on // but LuaJIT will swallow all C++ errors // if we don't at least catch std::exception ones @@ -184,8 +189,8 @@ namespace sol { #endif // LuaJIT #else // do not handle exceptions: they can be propogated into C++ and keep all type information / rich information -#endif // about as safe as possible -#endif // No Exceptions +#endif // Safe Exception Propagation +#endif // Exceptions vs. No Exceptions return protected_function_result(lua_state(), firstreturn, returncount, returncount, code); } diff --git a/sol/types.hpp b/sol/types.hpp index 21142ed6..b37cb67d 100644 --- a/sol/types.hpp +++ b/sol/types.hpp @@ -77,13 +77,16 @@ namespace sol { try { return f(L); } - catch (const char* s) { - lua_pushstring(L, s); + catch (const char* cs) { + lua_pushstring(L, cs); + } + catch (const std::string& s) { + lua_pushlstring(L, s.c_str(), s.size()); } catch (const std::exception& e) { lua_pushstring(L, e.what()); } -#if defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && defined(SOL_LUAJIT) +#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) // LuaJIT cannot have the catchall when the safe propagation is on // but LuaJIT will swallow all C++ errors // if we don't at least catch std::exception ones @@ -92,7 +95,7 @@ namespace sol { } #endif // LuaJIT cannot have the catchall, but we must catch std::exceps for it return lua_error(L); -#endif +#endif // Safe exceptions } #ifdef SOL_NOEXCEPT_FUNCTION_TYPE @@ -134,7 +137,7 @@ namespace sol { catch (const std::exception& e) { lua_pushstring(L, e.what()); } -#if defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && !defined(SOL_LUAJIT) +#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) // LuaJIT cannot have the catchall when the safe propagation is on // but LuaJIT will swallow all C++ errors // if we don't at least catch std::exception ones