From b24d17df314fdccdc63974e55ad12d4fb6084b22 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 2 Mar 2016 08:44:07 -0500 Subject: [PATCH] Allow for exceptions to not be used. --- .gitignore | 1 + sol/compatibility/version.hpp | 7 +++++++ sol/function.hpp | 6 ++++-- sol/types.hpp | 17 ++++++++++++++++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index ec45d9b8..da9e596c 100644 --- a/.gitignore +++ b/.gitignore @@ -53,3 +53,4 @@ lib/liblua5.2.a # Windows Crap desktop.ini +*.sublime-workspace diff --git a/sol/compatibility/version.hpp b/sol/compatibility/version.hpp index 53aa3f30..e96857e3 100644 --- a/sol/compatibility/version.hpp +++ b/sol/compatibility/version.hpp @@ -42,4 +42,11 @@ #define SOL_LUA_VERSION 502 #endif // Lua Version 502, 501 || luajit, 500 +#ifdef _MSC_VER +#if _HAS_EXCEPTIONS == 0 +// This means VC++ has no exceptions +// Maybe: automatically define SOL_NO_EXCEPTIONS ? +#endif // Automatic Exception Detection +#endif // VC++ Exception Mechanism + #endif // SOL_VERSION_HPP diff --git a/sol/function.hpp b/sol/function.hpp index 2837dfd7..9b756aa7 100644 --- a/sol/function.hpp +++ b/sol/function.hpp @@ -163,15 +163,16 @@ private: int firstreturn = std::max(1, stacksize - static_cast(n) - 1); int returncount = 0; call_status code = call_status::ok; - +#ifdef SOL_NO_EXCEPTIONS try { +#endif // No Exceptions code = static_cast(luacall(n, LUA_MULTRET, h)); int poststacksize = lua_gettop(lua_state()); returncount = poststacksize - firstreturn; +#ifdef SOL_NO_EXCEPTIONS } // Handle C++ errors thrown from C++ functions bound inside of lua catch (const char* error) { - h.stackindex = 0; stack::push(lua_state(), error); firstreturn = lua_gettop(lua_state()); return protected_function_result(lua_state(), firstreturn, 0, 1, call_status::runtime); @@ -185,6 +186,7 @@ private: catch (...) { throw; } +#endif // No Exceptions return protected_function_result(lua_state(), firstreturn + ( handlerpushed ? 0 : 1 ), returncount, returncount, code); } diff --git a/sol/types.hpp b/sol/types.hpp index be09c1fa..5fba75be 100644 --- a/sol/types.hpp +++ b/sol/types.hpp @@ -28,7 +28,7 @@ namespace sol { namespace detail { - +#ifdef SOL_NO_EXCEPTIONS template inline int static_trampoline (lua_State* L) { try { @@ -66,6 +66,21 @@ inline int trampoline(lua_State* L, Fx&& f) { inline int c_trampoline(lua_State* L, lua_CFunction f) { return trampoline(L, f); } +#else +template +inline int static_trampoline (lua_State* L) { + return f(L); +} + +template +inline int trampoline(lua_State* L, Fx&& f) { + return f(L); +} + +inline int c_trampoline(lua_State* L, lua_CFunction f) { + return trampoline(L, f); +} +#endif // Exceptions vs. No Exceptions } struct nil_t {}; const nil_t nil {};