mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Allow for exceptions to not be used.
This commit is contained in:
parent
c350af8544
commit
b24d17df31
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -53,3 +53,4 @@ lib/liblua5.2.a
|
||||||
|
|
||||||
# Windows Crap
|
# Windows Crap
|
||||||
desktop.ini
|
desktop.ini
|
||||||
|
*.sublime-workspace
|
||||||
|
|
|
@ -42,4 +42,11 @@
|
||||||
#define SOL_LUA_VERSION 502
|
#define SOL_LUA_VERSION 502
|
||||||
#endif // Lua Version 502, 501 || luajit, 500
|
#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
|
#endif // SOL_VERSION_HPP
|
||||||
|
|
|
@ -163,15 +163,16 @@ private:
|
||||||
int firstreturn = std::max(1, stacksize - static_cast<int>(n) - 1);
|
int firstreturn = std::max(1, stacksize - static_cast<int>(n) - 1);
|
||||||
int returncount = 0;
|
int returncount = 0;
|
||||||
call_status code = call_status::ok;
|
call_status code = call_status::ok;
|
||||||
|
#ifdef SOL_NO_EXCEPTIONS
|
||||||
try {
|
try {
|
||||||
|
#endif // No Exceptions
|
||||||
code = static_cast<call_status>(luacall(n, LUA_MULTRET, h));
|
code = static_cast<call_status>(luacall(n, LUA_MULTRET, h));
|
||||||
int poststacksize = lua_gettop(lua_state());
|
int poststacksize = lua_gettop(lua_state());
|
||||||
returncount = poststacksize - firstreturn;
|
returncount = poststacksize - firstreturn;
|
||||||
|
#ifdef SOL_NO_EXCEPTIONS
|
||||||
}
|
}
|
||||||
// Handle C++ errors thrown from C++ functions bound inside of lua
|
// Handle C++ errors thrown from C++ functions bound inside of lua
|
||||||
catch (const char* error) {
|
catch (const char* error) {
|
||||||
h.stackindex = 0;
|
|
||||||
stack::push(lua_state(), error);
|
stack::push(lua_state(), error);
|
||||||
firstreturn = lua_gettop(lua_state());
|
firstreturn = lua_gettop(lua_state());
|
||||||
return protected_function_result(lua_state(), firstreturn, 0, 1, call_status::runtime);
|
return protected_function_result(lua_state(), firstreturn, 0, 1, call_status::runtime);
|
||||||
|
@ -185,6 +186,7 @@ private:
|
||||||
catch (...) {
|
catch (...) {
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
#endif // No Exceptions
|
||||||
return protected_function_result(lua_state(), firstreturn + ( handlerpushed ? 0 : 1 ), returncount, returncount, code);
|
return protected_function_result(lua_state(), firstreturn + ( handlerpushed ? 0 : 1 ), returncount, returncount, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
namespace sol {
|
namespace sol {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
#ifdef SOL_NO_EXCEPTIONS
|
||||||
template <lua_CFunction f>
|
template <lua_CFunction f>
|
||||||
inline int static_trampoline (lua_State* L) {
|
inline int static_trampoline (lua_State* L) {
|
||||||
try {
|
try {
|
||||||
|
@ -66,6 +66,21 @@ inline int trampoline(lua_State* L, Fx&& f) {
|
||||||
inline int c_trampoline(lua_State* L, lua_CFunction f) {
|
inline int c_trampoline(lua_State* L, lua_CFunction f) {
|
||||||
return trampoline(L, f);
|
return trampoline(L, f);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
template <lua_CFunction f>
|
||||||
|
inline int static_trampoline (lua_State* L) {
|
||||||
|
return f(L);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Fx>
|
||||||
|
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 {};
|
struct nil_t {};
|
||||||
const nil_t nil {};
|
const nil_t nil {};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user