diff --git a/examples/source/customization_multiple.cpp b/examples/source/customization_multiple.cpp index 2d5ae0f5..e6c5c9e3 100644 --- a/examples/source/customization_multiple.cpp +++ b/examples/source/customization_multiple.cpp @@ -14,7 +14,7 @@ bool sol_lua_check(sol::types, lua_State* L, int index, Handler&& ha // indices can be negative to count backwards from the top of the stack, // rather than the bottom up // to deal with this, we adjust the index to - // its absolute position using the lua_absindex function + // its absolute position using the lua_absindex function int absolute_index = lua_absindex(L, index); // Check first and second second index for being the proper types bool success = sol::stack::check(L, absolute_index, handler) && sol::stack::check(L, absolute_index + 1, handler); @@ -26,15 +26,15 @@ two_things sol_lua_get(sol::types, lua_State* L, int index, sol::sta int absolute_index = lua_absindex(L, index); // Get the first element int a = sol::stack::get(L, absolute_index); - // Get the second element, + // Get the second element, // in the +1 position from the first bool b = sol::stack::get(L, absolute_index + 1); // we use 2 slots, each of the previous takes 1 tracking.use(2); - return two_things{ a, b }; + return two_things { a, b }; } -int sol_lua_push(sol::types, lua_State* L, const two_things& things) { +int sol_lua_push(lua_State* L, const two_things& things) { int amount = sol::stack::push(L, things.a); // amount will be 1: int pushes 1 item amount += sol::stack::push(L, things.b); @@ -46,7 +46,7 @@ int sol_lua_push(sol::types, lua_State* L, const two_things& things) int main() { std::cout << "=== customization ===" << std::endl; std::cout << std::boolalpha; - + sol::state lua; lua.open_libraries(sol::lib::base); @@ -56,7 +56,7 @@ int main() { // get the function out of Lua sol::function f = lua["f"]; - two_things things = f(two_things{ 24, false }); + two_things things = f(two_things { 24, false }); c_assert(things.a == 24); c_assert(things.b == false); // things.a == 24 diff --git a/include/sol/compatibility.hpp b/include/sol/compatibility.hpp index e7f9928f..1ef761f3 100644 --- a/include/sol/compatibility.hpp +++ b/include/sol/compatibility.hpp @@ -32,7 +32,7 @@ #include #include -#if !defined(SOL_NO_COMPAT) || !(SOL_NO_COMPAT) +#if SOL_IS_ON(SOL_USE_COMPATIBILITY_LAYER_I_) #if SOL_IS_ON(SOL_USE_CXX_LUA_I_) || SOL_IS_ON(SOL_USE_CXX_LUAJIT_I_) #ifndef COMPAT53_LUA_CPP @@ -46,6 +46,6 @@ #include #include -#endif // SOL_NO_COMPAT +#endif #endif // SOL_COMPATIBILITY_HPP diff --git a/include/sol/compatibility/lua_version.hpp b/include/sol/compatibility/lua_version.hpp index 38ed3a9b..0d939d0f 100644 --- a/include/sol/compatibility/lua_version.hpp +++ b/include/sol/compatibility/lua_version.hpp @@ -51,7 +51,7 @@ #elif defined(LUAJIT_VERSION) #define SOL_USE_LUAJIT_I_ SOL_OFF #else - #define SOL_USE_LUAJIT_I_ SOL_OFF + #define SOL_USE_LUAJIT_I_ SOL_DEFAULT_OFF #endif // luajit #if SOL_IS_ON(SOL_USE_CXX_LUAJIT_I_) @@ -71,9 +71,9 @@ #endif #if defined(MOONJIT_VERSION) - #define SOL_MOONJIT_I_ SOL_ON + #define SOL_USE_MOONJIT_I_ SOL_ON #else - #define SOL_MOONJIT_I_ SOL_OFF + #define SOL_USE_MOONJIT_I_ SOL_OFF #endif #if !defined(SOL_LUA_VERSION) @@ -98,10 +98,18 @@ // Exception safety / propagation, according to Lua information // and user defines. Note this can sometimes change based on version information... -#if defined(SOL_EXCEPTIONS_ALWAYS_UNSAFE) && (SOL_EXCEPTIONS_ALWAYS_UNSAFE != 0) - #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_OFF -#elif defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && (SOL_EXCEPTIONS_SAFE_PROPAGATION != 0) - #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_ON +#if defined(SOL_EXCEPTIONS_ALWAYS_UNSAFE) + #if (SOL_EXCEPTIONS_ALWAYS_UNSAFE != 0) + #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_OFF + #else + #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_ON + #endif +#elif defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) + #if (SOL_EXCEPTIONS_SAFE_PROPAGATION != 0) + #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_ON + #else + #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_OFF + #endif #elif SOL_LUAJIT_VERSION_I_ >= 20100 // LuaJIT 2.1.0-beta3 and better have exception support locked in for all platforms (mostly) #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_DEFAULT_ON @@ -116,9 +124,37 @@ // otherwise, there is no exception safety for // shoving exceptions through Lua and errors should // always be serialized - #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_OFF + #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_DEFAULT_OFF #endif // LuaJIT beta 02.01.00 have better exception handling on all platforms since beta3 +#if defined(SOL_LUAJIT_USE_EXCEPTION_TRAMPOLINE) + #if (SOL_LUAJIT_USE_EXCEPTION_TRAMPOLINE != 0) + #define SOL_USE_LUAJIT_EXCEPTION_TRAMPOLINE_I_ SOL_ON + #else + #define SOL_USE_LUAJIT_EXCEPTION_TRAMPOLINE_I_ SOL_OFF + #endif +#else + #if SOL_IS_OFF(SOL_PROPAGATE_EXCEPTIONS_I_) && SOL_IS_ON(SOL_USE_LUAJIT_I_) + #define SOL_USE_LUAJIT_EXCEPTION_TRAMPOLINE_I_ SOL_ON + #else + #define SOL_USE_LUAJIT_EXCEPTION_TRAMPOLINE_I_ SOL_DEFAULT_OFF + #endif +#endif + +#if defined(SOL_LUAL_STREAM_HAS_CLOSE_FUNCTION) + #if (SOL_LUAL_STREAM_HAS_CLOSE_FUNCTION != 0) + #define SOL_LUAL_STREAM_USE_CLOSE_FUNCTION_I_ SOL_ON + #else + #define SOL_LUAL_STREAM_USE_CLOSE_FUNCTION_I_ SOL_OFF + #endif +#else + #if SOL_IS_OFF(SOL_USE_LUAJIT_I_) && (SOL_LUA_VERSION > 501) + #define SOL_LUAL_STREAM_USE_CLOSE_FUNCTION_I_ SOL_ON + #else + #define SOL_LUAL_STREAM_USE_CLOSE_FUNCTION_I_ SOL_DEFAULT_OFF + #endif +#endif + // clang-format on #endif // SOL_COMPATIBILITY_VERSION_HPP diff --git a/include/sol/coroutine.hpp b/include/sol/coroutine.hpp index 0b4d901f..aad5c01c 100644 --- a/include/sol/coroutine.hpp +++ b/include/sol/coroutine.hpp @@ -45,7 +45,7 @@ namespace sol { call_status stats = call_status::yielded; void luacall(std::ptrdiff_t argcount, std::ptrdiff_t) { -#if SOL_LUA_VERSION >= 504 +#if SOL_LUA_VESION_I_ >= 504 int nresults; stats = static_cast(lua_resume(lua_state(), nullptr, static_cast(argcount), &nresults)); #else @@ -91,13 +91,16 @@ namespace sol { using base_t::lua_state; basic_coroutine() = default; - template , basic_coroutine>>, meta::neg>>, meta::neg>, meta::neg>>, is_lua_reference>> = meta::enabler> + template , basic_coroutine>>, + meta::neg>>, meta::neg>, + meta::neg>>, is_lua_reference>> = meta::enabler> basic_coroutine(T&& r) noexcept : base_t(std::forward(r)), error_handler(detail::get_default_handler::value>(r.lua_state())) { #if SOL_IS_ON(SOL_SAFE_REFERENCES_I_) if (!is_function>::value) { auto pp = stack::push_pop(*this); - constructor_handler handler{}; + constructor_handler handler {}; stack::check(lua_state(), -1, handler); } #endif // Safety @@ -112,11 +115,9 @@ namespace sol { basic_coroutine(basic_function&& b) : basic_coroutine(std::move(b), detail::get_default_handler::value>(b.lua_state())) { } - basic_coroutine(const basic_function& b, handler_t eh) - : base_t(b), error_handler(std::move(eh)) { + basic_coroutine(const basic_function& b, handler_t eh) : base_t(b), error_handler(std::move(eh)) { } - basic_coroutine(basic_function&& b, handler_t eh) - : base_t(std::move(b)), error_handler(std::move(eh)) { + basic_coroutine(basic_function&& b, handler_t eh) : base_t(std::move(b)), error_handler(std::move(eh)) { } basic_coroutine(const stack_reference& r) : basic_coroutine(r.lua_state(), r.stack_index(), detail::get_default_handler::value>(r.lua_state())) { @@ -124,11 +125,9 @@ namespace sol { basic_coroutine(stack_reference&& r) : basic_coroutine(r.lua_state(), r.stack_index(), detail::get_default_handler::value>(r.lua_state())) { } - basic_coroutine(const stack_reference& r, handler_t eh) - : basic_coroutine(r.lua_state(), r.stack_index(), std::move(eh)) { + basic_coroutine(const stack_reference& r, handler_t eh) : basic_coroutine(r.lua_state(), r.stack_index(), std::move(eh)) { } - basic_coroutine(stack_reference&& r, handler_t eh) - : basic_coroutine(r.lua_state(), r.stack_index(), std::move(eh)) { + basic_coroutine(stack_reference&& r, handler_t eh) : basic_coroutine(r.lua_state(), r.stack_index(), std::move(eh)) { } template @@ -139,9 +138,9 @@ namespace sol { basic_coroutine(proxy_base&& p) : basic_coroutine(std::move(p), detail::get_default_handler::value>(p.lua_state())) { } - template >, meta::neg>>> = meta::enabler> - basic_coroutine(Proxy&& p, Handler&& eh) - : basic_coroutine(detail::force_cast(p), std::forward(eh)) { + template >, meta::neg>>> = meta::enabler> + basic_coroutine(Proxy&& p, Handler&& eh) : basic_coroutine(detail::force_cast(p), std::forward(eh)) { } template >> = meta::enabler> @@ -149,57 +148,51 @@ namespace sol { : basic_coroutine(L, std::forward(r), detail::get_default_handler::value>(L)) { } template >> = meta::enabler> - basic_coroutine(lua_State* L, T&& r, handler_t eh) - : base_t(L, std::forward(r)), error_handler(std::move(eh)) { + basic_coroutine(lua_State* L, T&& r, handler_t eh) : base_t(L, std::forward(r)), error_handler(std::move(eh)) { #if SOL_IS_ON(SOL_SAFE_REFERENCES_I_) auto pp = stack::push_pop(*this); - constructor_handler handler{}; + constructor_handler handler {}; stack::check(lua_state(), -1, handler); #endif // Safety } - basic_coroutine(lua_nil_t n) - : base_t(n), error_handler(n) { + basic_coroutine(lua_nil_t n) : base_t(n), error_handler(n) { } basic_coroutine(lua_State* L, int index = -1) : basic_coroutine(L, index, detail::get_default_handler::value>(L)) { } - basic_coroutine(lua_State* L, int index, handler_t eh) - : base_t(L, index), error_handler(std::move(eh)) { + basic_coroutine(lua_State* L, int index, handler_t eh) : base_t(L, index), error_handler(std::move(eh)) { #ifdef SOL_SAFE_REFERENCES - constructor_handler handler{}; + constructor_handler handler {}; stack::check(L, index, handler); #endif // Safety } basic_coroutine(lua_State* L, absolute_index index) : basic_coroutine(L, index, detail::get_default_handler::value>(L)) { } - basic_coroutine(lua_State* L, absolute_index index, handler_t eh) - : base_t(L, index), error_handler(std::move(eh)) { + basic_coroutine(lua_State* L, absolute_index index, handler_t eh) : base_t(L, index), error_handler(std::move(eh)) { #if SOL_IS_ON(SOL_SAFE_REFERENCES_I_) - constructor_handler handler{}; + constructor_handler handler {}; stack::check(L, index, handler); #endif // Safety } basic_coroutine(lua_State* L, raw_index index) : basic_coroutine(L, index, detail::get_default_handler::value>(L)) { } - basic_coroutine(lua_State* L, raw_index index, handler_t eh) - : base_t(L, index), error_handler(std::move(eh)) { + basic_coroutine(lua_State* L, raw_index index, handler_t eh) : base_t(L, index), error_handler(std::move(eh)) { #if SOL_IS_ON(SOL_SAFE_REFERENCES_I_) - constructor_handler handler{}; + constructor_handler handler {}; stack::check(L, index, handler); #endif // Safety } basic_coroutine(lua_State* L, ref_index index) : basic_coroutine(L, index, detail::get_default_handler::value>(L)) { } - basic_coroutine(lua_State* L, ref_index index, handler_t eh) - : base_t(L, index), error_handler(std::move(eh)) { + basic_coroutine(lua_State* L, ref_index index, handler_t eh) : base_t(L, index), error_handler(std::move(eh)) { #if SOL_IS_ON(SOL_SAFE_REFERENCES_I_) auto pp = stack::push_pop(*this); - constructor_handler handler{}; + constructor_handler handler {}; stack::check(lua_state(), -1, handler); #endif // Safety } @@ -214,8 +207,7 @@ namespace sol { } bool runnable() const noexcept { - return base_t::valid() - && (status() == call_status::yielded); + return base_t::valid() && (status() == call_status::yielded); } explicit operator bool() const noexcept { diff --git a/include/sol/demangle.hpp b/include/sol/demangle.hpp index b8a325a1..246b9696 100644 --- a/include/sol/demangle.hpp +++ b/include/sol/demangle.hpp @@ -28,16 +28,15 @@ #include #include #include -#if defined(__GNUC__) && defined(__MINGW32__) && (__GNUC__ < 6) +#if SOL_IS_ON(SOL_MINGW_CCTYPE_IS_POISONED_I_) extern "C" { #include } #endif // MinGW is on some stuff #include -namespace sol { -namespace detail { - inline constexpr std::array removals{ { "{anonymous}", +namespace sol { namespace detail { + inline constexpr std::array removals { { "{anonymous}", "(anonymous namespace)", "public:", "private:", @@ -48,7 +47,7 @@ namespace detail { "`anonymous namespace'" } }; -#if defined(__GNUC__) || defined(__clang__) +#if SOL_IS_ON(SOL_COMPILER_GCC_I_) || SOL_IS_ON(SOL_COMPILER_CLANG_I_) inline std::string ctti_get_type_name_from_sig(std::string name) { // cardinal sins from MINGW using namespace std; @@ -86,7 +85,7 @@ namespace detail { inline std::string ctti_get_type_name() { return ctti_get_type_name_from_sig(__PRETTY_FUNCTION__); } -#elif defined(_MSC_VER) +#elif SOL_IS_ON(SOL_COMPILER_VCXX_I_) inline std::string ctti_get_type_name_from_sig(std::string name) { std::size_t start = name.find("get_type_name"); if (start == std::string::npos) @@ -135,7 +134,9 @@ namespace detail { inline std::string short_demangle_from_type_name(std::string realname) { // This isn't the most complete but it'll do for now...? - static const std::array ops = {{"operator<", "operator<<", "operator<<=", "operator<=", "operator>", "operator>>", "operator>>=", "operator>=", "operator->", "operator->*"}}; + static const std::array ops = { + { "operator<", "operator<<", "operator<<=", "operator<=", "operator>", "operator>>", "operator>>=", "operator>=", "operator->", "operator->*" } + }; int level = 0; std::ptrdiff_t idx = 0; for (idx = static_cast(realname.empty() ? 0 : realname.size() - 1); idx > 0; --idx) { @@ -186,7 +187,6 @@ namespace detail { static const std::string d = short_demangle_once(); return d; } -} -} // namespace sol::detail +}} // namespace sol::detail #endif // SOL_DEMANGLE_HPP diff --git a/include/sol/environment.hpp b/include/sol/environment.hpp index 5d779156..0141f9de 100644 --- a/include/sol/environment.hpp +++ b/include/sol/environment.hpp @@ -1,4 +1,4 @@ -// sol3 +// sol3 // The MIT License (MIT) @@ -41,19 +41,15 @@ namespace sol { basic_environment(basic_environment&&) = default; basic_environment& operator=(const basic_environment&) = default; basic_environment& operator=(basic_environment&&) = default; - basic_environment(const stack_reference& r) - : basic_environment(r.lua_state(), r.stack_index()) { + basic_environment(const stack_reference& r) : basic_environment(r.lua_state(), r.stack_index()) { } - basic_environment(stack_reference&& r) - : basic_environment(r.lua_state(), r.stack_index()) { + basic_environment(stack_reference&& r) : basic_environment(r.lua_state(), r.stack_index()) { } - basic_environment(lua_State* L, new_table nt) - : base_t(L, std::move(nt)) { + basic_environment(lua_State* L, new_table nt) : base_t(L, std::move(nt)) { } template - basic_environment(lua_State* L, new_table t, const basic_reference& fallback) - : basic_environment(L, std::move(t)) { + basic_environment(lua_State* L, new_table t, const basic_reference& fallback) : basic_environment(L, std::move(t)) { stack_table mt(L, new_table(0, 1)); mt.set(meta_function::index, fallback); this->set(metatable_key, mt); @@ -63,7 +59,7 @@ namespace sol { basic_environment(env_key_t, const stack_reference& extraction_target) : base_t(detail::no_safety, extraction_target.lua_state(), (stack::push_environment_of(extraction_target), -1)) { #if SOL_IS_ON(SOL_SAFE_REFERENCES_I_) - constructor_handler handler{}; + constructor_handler handler {}; stack::check(this->lua_state(), -1, handler); #endif // Safety lua_pop(this->lua_state(), 2); @@ -72,48 +68,45 @@ namespace sol { basic_environment(env_key_t, const basic_reference& extraction_target) : base_t(detail::no_safety, extraction_target.lua_state(), (stack::push_environment_of(extraction_target), -1)) { #if SOL_IS_ON(SOL_SAFE_REFERENCES_I_) - constructor_handler handler{}; + constructor_handler handler {}; stack::check(this->lua_state(), -1, handler); #endif // Safety lua_pop(this->lua_state(), 2); } - basic_environment(lua_State* L, int index = -1) - : base_t(detail::no_safety, L, index) { + basic_environment(lua_State* L, int index = -1) : base_t(detail::no_safety, L, index) { #if SOL_IS_ON(SOL_SAFE_REFERENCES_I_) - constructor_handler handler{}; + constructor_handler handler {}; stack::check(L, index, handler); #endif // Safety } - basic_environment(lua_State* L, ref_index index) - : base_t(detail::no_safety, L, index) { + basic_environment(lua_State* L, ref_index index) : base_t(detail::no_safety, L, index) { #if SOL_IS_ON(SOL_SAFE_REFERENCES_I_) auto pp = stack::push_pop(*this); - constructor_handler handler{}; + constructor_handler handler {}; stack::check(L, -1, handler); #endif // Safety } - template , basic_environment>>, meta::neg>, meta::neg>>, is_lua_reference>> = meta::enabler> - basic_environment(T&& r) noexcept - : base_t(detail::no_safety, std::forward(r)) { + template , basic_environment>>, meta::neg>, + meta::neg>>, is_lua_reference>> = meta::enabler> + basic_environment(T&& r) noexcept : base_t(detail::no_safety, std::forward(r)) { #if SOL_IS_ON(SOL_SAFE_REFERENCES_I_) if (!is_environment>::value) { auto pp = stack::push_pop(*this); - constructor_handler handler{}; + constructor_handler handler {}; stack::check(lua_state(), -1, handler); } #endif // Safety } - basic_environment(lua_nil_t r) noexcept - : base_t(detail::no_safety, r) { + basic_environment(lua_nil_t r) noexcept : base_t(detail::no_safety, r) { } template >> = meta::enabler> - basic_environment(lua_State* L, T&& r) noexcept - : base_t(detail::no_safety, L, std::forward(r)) { + basic_environment(lua_State* L, T&& r) noexcept : base_t(detail::no_safety, L, std::forward(r)) { #if SOL_IS_ON(SOL_SAFE_REFERENCES_I_) if (!is_environment>::value) { auto pp = stack::push_pop(*this); - constructor_handler handler{}; + constructor_handler handler {}; stack::check(lua_state(), -1, handler); } #endif // Safety @@ -123,7 +116,7 @@ namespace sol { void set_on(const T& target) const { lua_State* L = target.lua_state(); auto pp = stack::push_pop(target); -#if SOL_LUA_VERSION < 502 +#if SOL_LUA_VESION_I_ < 502 // Use lua_setfenv this->push(); lua_setfenv(L, -2); @@ -153,11 +146,9 @@ namespace sol { struct this_environment { optional env; - this_environment() - : env(nullopt) { + this_environment() : env(nullopt) { } - this_environment(environment e) - : env(std::move(e)) { + this_environment(environment e) : env(std::move(e)) { } this_environment(const this_environment&) = default; this_environment(this_environment&&) = default; @@ -168,11 +159,11 @@ namespace sol { return static_cast(env); } - operator optional&() { + operator optional &() { return env; } - operator const optional&() const { + operator const optional &() const { return env; } diff --git a/include/sol/load_result.hpp b/include/sol/load_result.hpp index 35476ed9..f2ed6189 100644 --- a/include/sol/load_result.hpp +++ b/include/sol/load_result.hpp @@ -39,12 +39,18 @@ namespace sol { load_status err; public: - load_result() = default; + load_result() noexcept = default; load_result(lua_State* Ls, int stackindex = -1, int retnum = 0, int popnum = 0, load_status lerr = load_status::ok) noexcept : L(Ls), index(stackindex), returncount(retnum), popcount(popnum), err(lerr) { } - load_result(const load_result&) = default; - load_result& operator=(const load_result&) = default; + + // We do not want anyone to copy these around willy-nilly + // Will likely break people, but also will probably get rid of quiet bugs that have + // been lurking. (E.g., Vanilla Lua will just quietly discard over-pops and under-pops: + // LuaJIT and other Lua engines will implode and segfault at random later times.) + load_result(const load_result&) = delete; + load_result& operator=(const load_result&) = delete; + load_result(load_result&& o) noexcept : L(o.L), index(o.index), returncount(o.returncount), popcount(o.popcount), err(o.err) { // Must be manual, otherwise destructor will screw us // return count being 0 is enough to keep things clean diff --git a/include/sol/protected_function_result.hpp b/include/sol/protected_function_result.hpp index e57dbbb0..2f34cfa8 100644 --- a/include/sol/protected_function_result.hpp +++ b/include/sol/protected_function_result.hpp @@ -54,12 +54,18 @@ namespace sol { typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; - protected_function_result() = default; + protected_function_result() noexcept = default; protected_function_result(lua_State* Ls, int idx = -1, int retnum = 0, int popped = 0, call_status pferr = call_status::ok) noexcept : L(Ls), index(idx), returncount(retnum), popcount(popped), err(pferr) { } - protected_function_result(const protected_function_result&) = default; - protected_function_result& operator=(const protected_function_result&) = default; + + // We do not want anyone to copy these around willy-nilly + // Will likely break people, but also will probably get rid of quiet bugs that have + // been lurking. (E.g., Vanilla Lua will just quietly discard over-pops and under-pops: + // LuaJIT and other Lua engines will implode and segfault at random later times.) + protected_function_result(const protected_function_result&) = delete; + protected_function_result& operator=(const protected_function_result&) = delete; + protected_function_result(protected_function_result&& o) noexcept : L(o.L), index(o.index), returncount(o.returncount), popcount(o.popcount), err(o.err) { // Must be manual, otherwise destructor will screw us diff --git a/include/sol/reference.hpp b/include/sol/reference.hpp index d015c28f..b8629f56 100644 --- a/include/sol/reference.hpp +++ b/include/sol/reference.hpp @@ -68,8 +68,7 @@ namespace sol { lua_State* L; int index; int count; - push_popper_at(lua_State* luastate, int index = -1, int count = 1) - : L(luastate), index(index), count(count) { + push_popper_at(lua_State* luastate, int index = -1, int count = 1) : L(luastate), index(index), count(count) { } ~push_popper_at() { remove(L, index, count); @@ -80,8 +79,7 @@ namespace sol { struct push_popper_n { lua_State* L; int t; - push_popper_n(lua_State* luastate, int x) - : L(luastate), t(x) { + push_popper_n(lua_State* luastate, int x) : L(luastate), t(x) { } push_popper_n(const push_popper_n&) = delete; push_popper_n(push_popper_n&&) = default; @@ -91,7 +89,7 @@ namespace sol { lua_pop(L, t); } }; - + template <> struct push_popper_n { push_popper_n(lua_State*, int) { @@ -104,9 +102,7 @@ namespace sol { T t; int idx; - push_popper(T x) - : t(x), idx(lua_absindex(t.lua_state(), -t.push())) { - + push_popper(T x) : t(x), idx(lua_absindex(t.lua_state(), -t.push())) { } int index_of(const Tu&) { @@ -132,11 +128,11 @@ namespace sol { ~push_popper() { } }; - + template struct push_popper>>> { using Tu = meta::unqualified_t; - + push_popper(T) { } @@ -159,7 +155,7 @@ namespace sol { lua_State* L = x.lua_state(); return push_popper_at(L, lua_absindex(L, -c), c); } - + template push_popper_n pop_n(lua_State* L, int x) { return push_popper_n(L, x); @@ -167,7 +163,7 @@ namespace sol { } // namespace stack inline lua_State* main_thread(lua_State* L, lua_State* backup_if_unsupported = nullptr) { -#if SOL_LUA_VERSION < 502 +#if SOL_LUA_VESION_I_ < 502 if (L == nullptr) return backup_if_unsupported; lua_getglobal(L, detail::default_main_thread_name()); @@ -235,7 +231,7 @@ namespace sol { } protected: - int stack_index () const noexcept { + int stack_index() const noexcept { return -1; } @@ -319,8 +315,7 @@ namespace sol { stateless_reference(const stateless_reference& o) noexcept = delete; stateless_reference& operator=(const stateless_reference& r) noexcept = delete; - stateless_reference(stateless_reference&& o) noexcept - : ref(o.ref) { + stateless_reference(stateless_reference&& o) noexcept : ref(o.ref) { o.ref = LUA_NOREF; } @@ -437,8 +432,7 @@ namespace sol { : basic_reference(detail::pick_main_thread(L, L), detail::global_, detail::global_) { } - basic_reference(lua_State* L, detail::global_tag, detail::global_tag) noexcept - : stateless_reference(L, detail::global_), luastate(L) { + basic_reference(lua_State* L, detail::global_tag, detail::global_tag) noexcept : stateless_reference(L, detail::global_), luastate(L) { } basic_reference(lua_State* oL, const basic_reference& o) noexcept : stateless_reference(oL, o), luastate(oL) { @@ -458,18 +452,14 @@ namespace sol { public: basic_reference() noexcept = default; - basic_reference(lua_nil_t) noexcept - : basic_reference() { + basic_reference(lua_nil_t) noexcept : basic_reference() { } - basic_reference(const stack_reference& r) noexcept - : basic_reference(r.lua_state(), r.stack_index()) { + basic_reference(const stack_reference& r) noexcept : basic_reference(r.lua_state(), r.stack_index()) { } - basic_reference(stack_reference&& r) noexcept - : basic_reference(r.lua_state(), r.stack_index()) { + basic_reference(stack_reference&& r) noexcept : basic_reference(r.lua_state(), r.stack_index()) { } template - basic_reference(lua_State* L, const basic_reference& r) noexcept - : luastate(detail::pick_main_thread(L, L)) { + basic_reference(lua_State* L, const basic_reference& r) noexcept : luastate(detail::pick_main_thread(L, L)) { if (r.ref == LUA_REFNIL) { ref = LUA_REFNIL; return; @@ -487,8 +477,7 @@ namespace sol { } template - basic_reference(lua_State* L, basic_reference&& r) noexcept - : luastate(detail::pick_main_thread(L, L)) { + basic_reference(lua_State* L, basic_reference&& r) noexcept : luastate(detail::pick_main_thread(L, L)) { if (r.ref == LUA_REFNIL) { ref = LUA_REFNIL; return; @@ -507,8 +496,7 @@ namespace sol { r.luastate = nullptr; } - basic_reference(lua_State* L, const stack_reference& r) noexcept - : luastate(detail::pick_main_thread(L, L)) { + basic_reference(lua_State* L, const stack_reference& r) noexcept : luastate(detail::pick_main_thread(L, L)) { if (lua_state() == nullptr || r.lua_state() == nullptr || r.get_type() == type::none) { ref = LUA_NOREF; return; @@ -523,8 +511,7 @@ namespace sol { r.push(lua_state()); ref = luaL_ref(lua_state(), LUA_REGISTRYINDEX); } - basic_reference(lua_State* L, int index = -1) noexcept - : luastate(detail::pick_main_thread(L, L)) { + basic_reference(lua_State* L, int index = -1) noexcept : luastate(detail::pick_main_thread(L, L)) { // use L to stick with that state's execution stack #if SOL_IS_ON(SOL_SAFE_STACK_CHECK_I_) luaL_checkstack(L, 1, "not enough Lua stack space to push this reference value"); @@ -532,13 +519,11 @@ namespace sol { lua_pushvalue(L, index); ref = luaL_ref(L, LUA_REGISTRYINDEX); } - basic_reference(lua_State* L, ref_index index) noexcept - : luastate(detail::pick_main_thread(L, L)) { + basic_reference(lua_State* L, ref_index index) noexcept : luastate(detail::pick_main_thread(L, L)) { lua_rawgeti(lua_state(), LUA_REGISTRYINDEX, index.index); ref = luaL_ref(lua_state(), LUA_REGISTRYINDEX); } - basic_reference(lua_State* L, lua_nil_t) noexcept - : luastate(detail::pick_main_thread(L, L)) { + basic_reference(lua_State* L, lua_nil_t) noexcept : luastate(detail::pick_main_thread(L, L)) { } ~basic_reference() noexcept { @@ -547,12 +532,10 @@ namespace sol { deref(); } - basic_reference(const basic_reference& o) noexcept - : stateless_reference(o.copy()), luastate(o.lua_state()) { + basic_reference(const basic_reference& o) noexcept : stateless_reference(o.copy()), luastate(o.lua_state()) { } - basic_reference(basic_reference&& o) noexcept - : stateless_reference(std::move(o)), luastate(o.lua_state()) { + basic_reference(basic_reference&& o) noexcept : stateless_reference(std::move(o)), luastate(o.lua_state()) { o.luastate = nullptr; } diff --git a/include/sol/sol.hpp b/include/sol/sol.hpp index 9667e492..b453451c 100644 --- a/include/sol/sol.hpp +++ b/include/sol/sol.hpp @@ -22,27 +22,28 @@ #ifndef SOL_HPP #define SOL_HPP -#if defined(UE_BUILD_DEBUG) || defined(UE_BUILD_DEVELOPMENT) || defined(UE_BUILD_TEST) || defined(UE_BUILD_SHIPPING) || defined(UE_SERVER) -#define SOL_INSIDE_UNREAL +#include + +#if SOL_IS_ON(SOL_INSIDE_UNREAL_ENGINE_I_) #ifdef check #pragma push_macro("check") #undef check #endif #endif // Unreal Engine 4 Bullshit -#if defined(__GNUC__) +#if SOL_IS_ON(SOL_COMPILER_GCC_I_) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wshadow" #pragma GCC diagnostic ignored "-Wconversion" #if __GNUC__ > 6 #pragma GCC diagnostic ignored "-Wnoexcept-type" #endif -#elif defined(__clang__) +#elif SOL_IS_ON(SOL_COMPILER_CLANG_I_) // we'll just let this alone for now -#elif defined _MSC_VER +#elif SOL_IS_ON(SOL_COMPILER_VCXX_I_) #pragma warning(push) #pragma warning(disable : 4505) // unreferenced local function has been removed GEE THANKS -#endif // clang++ vs. g++ vs. VC++ +#endif // clang++ vs. g++ vs. VC++ #include #include @@ -63,13 +64,13 @@ #include #include -#if defined(__GNUC__) +#if SOL_IS_ON(SOL_COMPILER_GCC_I_) #pragma GCC diagnostic pop -#elif defined _MSC_VER +#elif SOL_IS_ON(SOL_COMPILER_VCXX_I_) #pragma warning(pop) #endif // g++ -#if defined(SOL_INSIDE_UNREAL) +#if SOL_IS_ON(SOL_INSIDE_UNREAL_ENGINE_I_) #undef check #pragma pop_macro("check") #endif // Unreal Engine 4 Bullshit diff --git a/include/sol/stack.hpp b/include/sol/stack.hpp index 098c705d..c7ee5c3c 100644 --- a/include/sol/stack.hpp +++ b/include/sol/stack.hpp @@ -272,7 +272,7 @@ namespace sol { } inline void luajit_exception_handler(lua_State* L, int (*handler)(lua_State*, lua_CFunction) = detail::c_trampoline) { -#if defined(SOL_LUAJIT) && (!defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) || !(SOL_EXCEPTIONS_SAFE_PROPAGATION)) +#if SOL_IS_ON(SOL_USE_LUAJIT_EXCEPTION_TRAMPOLINE_I_) if (L == nullptr) { return; } @@ -289,7 +289,7 @@ namespace sol { } inline void luajit_exception_off(lua_State* L) { -#if defined(SOL_LUAJIT) +#if SOL_IS_ON(SOL_USE_LUAJIT_EXCEPTION_TRAMPOLINE_I_) if (L == nullptr) { return; } diff --git a/include/sol/stack_check_get_unqualified.hpp b/include/sol/stack_check_get_unqualified.hpp index f5c2a052..57116f2f 100644 --- a/include/sol/stack_check_get_unqualified.hpp +++ b/include/sol/stack_check_get_unqualified.hpp @@ -58,7 +58,7 @@ namespace sol { namespace stack { return stack_detail::unchecked_get(L, index, tracking); } else if constexpr ((std::is_integral_v || std::is_same_v)&&!std::is_same_v) { -#if SOL_LUA_VERSION >= 503 +#if SOL_LUA_VESION_I_ >= 503 if (lua_isinteger(L, index) != 0) { tracking.use(1); return static_cast(lua_tointeger(L, index)); @@ -67,7 +67,7 @@ namespace sol { namespace stack { int isnum = 0; const lua_Number value = lua_tonumberx(L, index, &isnum); if (isnum != 0) { -#if (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) && !(defined(SOL_NO_CHECK_NUMBER_PRECISION) && SOL_NO_CHECK_NUMBER_PRECISION) +#if SOL_IS_ON(SOL_NUMBER_PRECISION_CHECKS_I_) const auto integer_value = llround(value); if (static_cast(integer_value) == value) { tracking.use(1); diff --git a/include/sol/stack_check_unqualified.hpp b/include/sol/stack_check_unqualified.hpp index 41c61ba9..c5959089 100644 --- a/include/sol/stack_check_unqualified.hpp +++ b/include/sol/stack_check_unqualified.hpp @@ -105,8 +105,10 @@ namespace sol { namespace stack { } else if constexpr (std::is_integral_v || std::is_same_v) { tracking.use(1); -#if SOL_LUA_VERSION >= 503 +#if SOL_LUA_VESION_I_ >= 503 + // Lua 5.3 and greater checks for numeric precision #if SOL_IS_ON(SOL_STRINGS_ARE_NUMBERS_I_) + // imprecise, sloppy conversions int isnum = 0; lua_tointegerx(L, index, &isnum); const bool success = isnum != 0; @@ -114,8 +116,8 @@ namespace sol { namespace stack { // expected type, actual type handler(L, index, type::number, type_of(L, index), detail::not_a_number_or_number_string_integral); } -#elif (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) && !(defined(SOL_NO_CHECK_NUMBER_PRECISION) && SOL_NO_CHECK_NUMBER_PRECISION) - // this check is precise, does not convert +#elif SOL_IS_ON(SOL_NUMBER_PRECISION_CHECKS_I_) + // this check is precise, do not convert if (lua_isinteger(L, index) == 1) { return true; } @@ -125,16 +127,18 @@ namespace sol { namespace stack { handler(L, index, type::number, type_of(L, index), detail::not_a_number_integral); } #else + // Numerics are neither safe nor string-convertible type t = type_of(L, index); const bool success = t == type::number; -#endif // If numbers are enabled, use the imprecise check +#endif if (!success) { // expected type, actual type handler(L, index, type::number, type_of(L, index), detail::not_a_number); } return success; #else -#if !defined(SOL_STRINGS_ARE_NUMBERS) || !SOL_STRINGS_ARE_NUMBERS + // Lua 5.2 and below checks +#if SOL_IS_OFF(SOL_STRINGS_ARE_NUMBERS_I_) // must pre-check, because it will convert type t = type_of(L, index); if (t != type::number) { @@ -143,7 +147,8 @@ namespace sol { namespace stack { return false; } #endif // Do not allow strings to be numbers -#if (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) && !(defined(SOL_NO_CHECK_NUMBER_PRECISION) && SOL_NO_CHECK_NUMBER_PRECISION) + +#if SOL_IS_ON(SOL_NUMBER_PRECISION_CHECKS_I_) int isnum = 0; const lua_Number v = lua_tonumberx(L, index, &isnum); const bool success = isnum != 0 && static_cast(llround(v)) == v; @@ -151,17 +156,17 @@ namespace sol { namespace stack { const bool success = true; #endif // Safe numerics and number precision checking if (!success) { - // expected type, actual type + // Use defines to provide a better error message! #if SOL_IS_ON(SOL_STRINGS_ARE_NUMBERS_I_) handler(L, index, type::number, type_of(L, index), detail::not_a_number_or_number_string); -#elif (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) +#elif SOL_IS_ON(SOL_NUMBER_PRECISION_CHECKS_I_) handler(L, index, type::number, t, detail::not_a_number_or_number_string); #else handler(L, index, type::number, t, detail::not_a_number); #endif } return success; -#endif // Lua Version 5.3 versus others +#endif } else if constexpr (std::is_floating_point_v || std::is_same_v) { tracking.use(1); @@ -461,7 +466,7 @@ namespace sol { namespace stack { }; template - struct unqualified_checker, type::userdata> : unqualified_checker> {}; + struct unqualified_checker, type::userdata> : unqualified_checker> { }; template struct unqualified_checker, type::userdata> { diff --git a/include/sol/stack_field.hpp b/include/sol/stack_field.hpp index 6a8f495e..2f4bdac3 100644 --- a/include/sol/stack_field.hpp +++ b/include/sol/stack_field.hpp @@ -33,11 +33,11 @@ namespace sol { namespace stack { template struct field_getter { static constexpr int default_table_index = meta::conditional_t < meta::is_c_str_v -#if SOL_LUA_VERSION >= 503 +#if SOL_LUA_VESION_I_ >= 503 || (std::is_integral_v && !std::is_same_v) #endif // integer global keys 5.3 or better || (raw && std::is_void_v>), - std::integral_constant, std::integral_constant> ::value; + std::integral_constant, std::integral_constant > ::value; template void get(lua_State* L, Key&& key, int tableindex = default_table_index) { @@ -48,7 +48,7 @@ namespace sol { namespace stack { } else if constexpr (std::is_same_v) { (void)key; -#if SOL_LUA_VERSION < 502 +#if SOL_LUA_VESION_I_ < 502 // Use lua_setfenv lua_getfenv(L, tableindex); #else @@ -67,7 +67,7 @@ namespace sol { namespace stack { if constexpr (std::is_integral_v && !std::is_same_v) { lua_rawgeti(L, tableindex, static_cast(key)); } -#if SOL_LUA_VERSION >= 502 +#if SOL_LUA_VESION_I_ >= 502 else if constexpr (std::is_void_v>) { lua_rawgetp(L, tableindex, key); } @@ -87,7 +87,7 @@ namespace sol { namespace stack { lua_getfield(L, tableindex, &key[0]); } } -#if SOL_LUA_VERSION >= 503 +#if SOL_LUA_VESION_I_ >= 503 else if constexpr (std::is_integral_v && !std::is_same_v) { lua_geti(L, tableindex, static_cast(key)); } @@ -105,7 +105,7 @@ namespace sol { namespace stack { template void apply(std::index_sequence<0, I...>, lua_State* L, Keys&& keys, int tableindex) { get_field(L, std::get<0>(std::forward(keys)), tableindex); - void(detail::swallow{ (get_field(L, std::get(std::forward(keys))), 0)... }); + void(detail::swallow { (get_field(L, std::get(std::forward(keys))), 0)... }); reference saved(L, -1); lua_pop(L, static_cast(sizeof...(I))); saved.push(); @@ -148,7 +148,7 @@ namespace sol { namespace stack { static constexpr int default_table_index = meta::conditional_t < (meta::is_c_str_v || meta::is_string_of_v) || (std::is_integral_v && !std::is_same_v) || (std::is_integral_v && !std::is_same_v) || (raw && std::is_void_v>), - std::integral_constant, std::integral_constant> ::value; + std::integral_constant, std::integral_constant > ::value; template void set(lua_State* L, Key&& key, Value&& value, int tableindex = default_table_index) { @@ -168,7 +168,7 @@ namespace sol { namespace stack { push(L, std::forward(value)); lua_rawseti(L, tableindex, static_cast(key)); } -#if SOL_LUA_VERSION >= 502 +#if SOL_LUA_VESION_I_ >= 502 else if constexpr (std::is_void_v>) { push(L, std::forward(value)); lua_rawsetp(L, tableindex, std::forward(key)); @@ -192,7 +192,7 @@ namespace sol { namespace stack { lua_setfield(L, tableindex, &key[0]); } } -#if SOL_LUA_VERSION >= 503 +#if SOL_LUA_VESION_I_ >= 503 else if constexpr (std::is_integral_v && !std::is_same_v) { push(L, std::forward(value)); lua_seti(L, tableindex, static_cast(key)); diff --git a/include/sol/stack_get_unqualified.hpp b/include/sol/stack_get_unqualified.hpp index 6adbd5cf..2e2e1833 100644 --- a/include/sol/stack_get_unqualified.hpp +++ b/include/sol/stack_get_unqualified.hpp @@ -127,7 +127,7 @@ namespace sol { namespace stack { } else if constexpr (std::is_integral_v || std::is_same_v) { tracking.use(1); -#if SOL_LUA_VERSION >= 503 +#if SOL_LUA_VESION_I_ >= 503 if (lua_isinteger(L, index) != 0) { return static_cast(lua_tointeger(L, index)); } @@ -326,7 +326,7 @@ namespace sol { namespace stack { int index = lua_absindex(L, relindex); T cont; std::size_t idx = 0; -#if SOL_LUA_VERSION >= 503 +#if SOL_LUA_VESION_I_ >= 503 // This method is HIGHLY performant over regular table iteration // thanks to the Lua API changes in 5.3 // Questionable in 5.4 @@ -337,7 +337,7 @@ namespace sol { namespace stack { } bool isnil = false; for (int vi = 0; vi < lua_size::value; ++vi) { -#if defined(LUA_NILINTABLE) && LUA_NILINTABLE && SOL_LUA_VERSION >= 600 +#if defined(LUA_NILINTABLE) && LUA_NILINTABLE && SOL_LUA_VESION_I_ >= 600 #if SOL_IS_ON(SOL_SAFE_STACK_CHECK_I_) luaL_checkstack(L, 1, detail::not_enough_stack_space_generic); #endif // make sure stack doesn't overflow @@ -358,7 +358,7 @@ namespace sol { namespace stack { if (i == 0) { break; } -#if defined(LUA_NILINTABLE) && LUA_NILINTABLE && SOL_LUA_VERSION >= 600 +#if defined(LUA_NILINTABLE) && LUA_NILINTABLE && SOL_LUA_VESION_I_ >= 600 lua_pop(L, vi); #else lua_pop(L, (vi + 1)); @@ -368,7 +368,7 @@ namespace sol { namespace stack { } } if (isnil) { -#if defined(LUA_NILINTABLE) && LUA_NILINTABLE && SOL_LUA_VERSION >= 600 +#if defined(LUA_NILINTABLE) && LUA_NILINTABLE && SOL_LUA_VESION_I_ >= 600 #else lua_pop(L, lua_size::value); #endif @@ -476,7 +476,7 @@ namespace sol { namespace stack { C cont; auto at = cont.cbefore_begin(); std::size_t idx = 0; -#if SOL_LUA_VERSION >= 503 +#if SOL_LUA_VESION_I_ >= 503 // This method is HIGHLY performant over regular table iteration thanks to the Lua API changes in 5.3 for (lua_Integer i = 0;; i += lua_size::value, lua_pop(L, lua_size::value)) { if (idx >= cont.max_size()) { diff --git a/include/sol/stack_push.hpp b/include/sol/stack_push.hpp index 5583b8b0..88929585 100644 --- a/include/sol/stack_push.hpp +++ b/include/sol/stack_push.hpp @@ -83,7 +83,7 @@ namespace sol { namespace stack { #if SOL_IS_ON(SOL_SAFE_STACK_CHECK_I_) luaL_checkstack(L, 1, detail::not_enough_stack_space_environment); #endif // make sure stack doesn't overflow -#if SOL_LUA_VERSION < 502 +#if SOL_LUA_VESION_I_ < 502 // Use lua_getfenv lua_getfenv(L, index); #else @@ -265,13 +265,13 @@ namespace sol { namespace stack { #if SOL_IS_ON(SOL_SAFE_STACK_CHECK_I_) luaL_checkstack(L, 1, detail::not_enough_stack_space_integral); #endif // make sure stack doesn't overflow -#if SOL_LUA_VERSION >= 503 +#if SOL_LUA_VESION_I_ >= 503 if (stack_detail::integer_value_fits(value)) { lua_pushinteger(L, static_cast(value)); return 1; } #endif // Lua 5.3 and above -#if (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) && !(defined(SOL_NO_CHECK_NUMBER_PRECISION) && SOL_NO_CHECK_NUMBER_PRECISION) +#if SOL_IS_ON(SOL_NUMBER_PRECISION_CHECKS_I_) if (static_cast(llround(static_cast(value))) != value) { #if SOL_IS_OFF(SOL_EXCEPTIONS_I_) // Is this really worth it? @@ -297,7 +297,7 @@ namespace sol { namespace stack { luaL_Stream* source { std::forward(args)... }; luaL_Stream* stream = static_cast(lua_newuserdata(L, sizeof(luaL_Stream))); stream->f = source->f; -#if !defined(SOL_LUAJIT) && (SOL_LUA_VERSION > 501) +#if SOL_IS_ON(SOL_LUAL_STREAM_USE_CLOSE_FUNCTION_I_) stream->closef = source->closef; #endif // LuaJIT and Lua 5.1 and below do not have return 1; @@ -306,7 +306,7 @@ namespace sol { namespace stack { luaL_Stream& source(std::forward(args)...); luaL_Stream* stream = static_cast(lua_newuserdata(L, sizeof(luaL_Stream))); stream->f = source.f; -#if !defined(SOL_LUAJIT) && (SOL_LUA_VERSION > 501) +#if SOL_IS_ON(SOL_LUAL_STREAM_USE_CLOSE_FUNCTION_I_) stream->closef = source.closef; #endif // LuaJIT and Lua 5.1 and below do not have return 1; @@ -376,7 +376,7 @@ namespace sol { namespace stack { int tableindex = lua_gettop(L); std::size_t index = 1; for (const auto& i : cont) { -#if SOL_LUA_VERSION >= 503 +#if SOL_LUA_VESION_I_ >= 503 int p = is_nested ? stack::push(L, as_nested_ref(i)) : stack::push(L, i); for (int pi = 0; pi < p; ++pi) { lua_seti(L, tableindex, static_cast(index++)); diff --git a/include/sol/state_handling.hpp b/include/sol/state_handling.hpp index 6a655555..3275a9c1 100644 --- a/include/sol/state_handling.hpp +++ b/include/sol/state_handling.hpp @@ -37,7 +37,7 @@ namespace sol { inline void register_main_thread(lua_State* L) { -#if SOL_LUA_VERSION < 502 +#if SOL_LUA_VESION_I_ < 502 if (L == nullptr) { lua_pushnil(L); lua_setglobal(L, detail::default_main_thread_name()); @@ -120,7 +120,7 @@ namespace sol { std::string err = "sol: "; err += to_string(result.status()); err += " error"; -#if !(defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS) +#if SOL_IS_ON(SOL_EXCEPTIONS_I_) std::exception_ptr eptr = std::current_exception(); if (eptr) { err += " with a "; diff --git a/include/sol/state_view.hpp b/include/sol/state_view.hpp index 3f34cbe3..c61aeed0 100644 --- a/include/sol/state_view.hpp +++ b/include/sol/state_view.hpp @@ -46,7 +46,7 @@ namespace sol { bool is53mod = loaded && !(loaded->is() && !loaded->as()); if (is53mod) return loaded; -#if SOL_LUA_VERSION <= 501 +#if SOL_LUA_VESION_I_ <= 501 auto loaded51 = global.traverse_get>("package", "loaded", key); bool is51mod = loaded51 && !(loaded51->is() && !loaded51->as()); if (is51mod) @@ -57,7 +57,7 @@ namespace sol { template void ensure_package(const std::string& key, T&& sr) { -#if SOL_LUA_VERSION <= 501 +#if SOL_LUA_VESION_I_ <= 501 auto pkg = global["package"]; if (!pkg.valid()) { pkg = create_table_with("loaded", create_table_with(key, sr)); @@ -120,7 +120,7 @@ namespace sol { for (auto&& library : libraries) { switch (library) { -#if SOL_LUA_VERSION <= 501 && defined(SOL_LUAJIT) +#if SOL_LUA_VESION_I_ <= 501 && defined(SOL_LUAJIT) case lib::coroutine: #endif // luajit opens coroutine base stuff case lib::base: @@ -133,7 +133,7 @@ namespace sol { break; #if !defined(SOL_LUAJIT) case lib::coroutine: -#if SOL_LUA_VERSION > 501 +#if SOL_LUA_VESION_I_ > 501 luaL_requiref(L, "coroutine", luaopen_coroutine, 1); lua_pop(L, 1); #endif // Lua 5.2+ only @@ -155,7 +155,7 @@ namespace sol { #ifdef SOL_LUAJIT luaL_requiref(L, "bit32", luaopen_bit, 1); lua_pop(L, 1); -#elif (SOL_LUA_VERSION == 502) || defined(LUA_COMPAT_BITLIB) || defined(LUA_COMPAT_5_2) +#elif (SOL_LUA_VESION_I_ == 502) || defined(LUA_COMPAT_BITLIB) || defined(LUA_COMPAT_5_2) luaL_requiref(L, "bit32", luaopen_bit32, 1); lua_pop(L, 1); #else @@ -174,7 +174,7 @@ namespace sol { lua_pop(L, 1); break; case lib::utf8: -#if SOL_LUA_VERSION > 502 && !defined(SOL_LUAJIT) +#if SOL_LUA_VESION_I_ > 502 && !defined(SOL_LUAJIT) luaL_requiref(L, "utf8", luaopen_utf8, 1); lua_pop(L, 1); #endif // Lua 5.3+ only @@ -227,7 +227,7 @@ namespace sol { // one day Lua 5.1 will die a peaceful death // and its old bones will find blissful rest auto loaders_proxy = package -#if SOL_LUA_VERSION < 502 +#if SOL_LUA_VESION_I_ < 502 ["loaders"] #else ["searchers"] @@ -255,7 +255,7 @@ namespace sol { // one day Lua 5.1 will die a peaceful death // and its old bones will find blissful rest auto loaders_proxy = package -#if SOL_LUA_VERSION < 502 +#if SOL_LUA_VESION_I_ < 502 ["loaders"] #else ["searchers"] @@ -638,7 +638,7 @@ namespace sol { } bool supports_gc_mode(gc_mode mode) const noexcept { -#if SOL_LUA_VERSION >= 504 +#if SOL_LUA_VESION_I_ >= 504 // supports all modes (void)mode; return true; @@ -647,7 +647,12 @@ namespace sol { } bool is_gc_on() const { +#if SOL_LUA_VESION_I_ >= 502 return lua_gc(lua_state(), LUA_GCISRUNNING, 0) == 1; +#else + // You cannot turn it off in Lua 5.1 + return true; +#endif } void collect_garbage() { @@ -662,7 +667,7 @@ namespace sol { // THOUGHT: std::chrono-alikes to map "kilobyte size" here...? // Make it harder to give MB or KB to a B parameter...? // Probably overkill for now. -#if SOL_LUA_VERSION >= 504 +#if SOL_LUA_VESION_I_ >= 504 // The manual implies that this function is almost always successful... // is it?? It could depend on the GC mode... return lua_gc(lua_state(), LUA_GCSTEP, step_size_kilobytes) != 0; @@ -687,7 +692,7 @@ namespace sol { // THOUGHT: std::chrono-alikes to map "byte size" here...? // Make it harder to give MB or KB to a B parameter...? // Probably overkill for now. -#if SOL_LUA_VERSION >= 504 +#if SOL_LUA_VESION_I_ >= 504 int old_mode = lua_gc(lua_state(), LUA_GCINC, pause, step_multiplier, step_byte_size); if (old_mode == LUA_GCGEN) { return gc_mode::generational; @@ -705,7 +710,7 @@ namespace sol { // Returns the old GC mode. Check support using the supports_gc_mode function. gc_mode change_gc_mode_generational(int minor_multiplier, int major_multiplier) { -#if SOL_LUA_VERSION >= 504 +#if SOL_LUA_VESION_I_ >= 504 // "What does this shit mean?" // http://www.lua.org/manual/5.4/manual.html#2.5.2 int old_mode = lua_gc(lua_state(), LUA_GCGEN, minor_multiplier, major_multiplier); diff --git a/include/sol/trampoline.hpp b/include/sol/trampoline.hpp index 0c3bdb86..11d893c5 100644 --- a/include/sol/trampoline.hpp +++ b/include/sol/trampoline.hpp @@ -1,4 +1,4 @@ -// sol3 +// sol3 // The MIT License (MIT) @@ -37,10 +37,10 @@ namespace sol { // must push a single object to be the error object // NOTE: the VAST MAJORITY of all Lua libraries -- C or otherwise -- expect a string for the type of error // break this convention at your own risk - using exception_handler_function = int(*)(lua_State*, optional, string_view); + using exception_handler_function = int (*)(lua_State*, optional, string_view); namespace detail { - inline const char(&default_exception_handler_name())[11]{ + inline const char (&default_exception_handler_name())[11] { static const char name[11] = "sol.\xE2\x98\xA2\xE2\x98\xA2"; return name; } @@ -72,13 +72,13 @@ namespace sol { return exfunc(L, std::move(maybe_ex), std::move(what)); } -#ifdef SOL_NO_EXCEPTIONS +#if SOL_IS_OFF(SOL_EXCEPTIONS_I_) template int static_trampoline(lua_State* L) noexcept { return f(L); } -#ifdef SOL_NOEXCEPT_FUNCTION_TYPE +#if SOL_IS_ON(SOL_USE_NOEXCEPT_FUNCTION_TYPE_I_) template int static_trampoline_noexcept(lua_State* L) noexcept { return f(L); @@ -100,8 +100,8 @@ namespace sol { } #else - inline int impl_static_trampoline(lua_State* L, lua_CFunction f) { -#if defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && !defined(SOL_LUAJIT) + inline int lua_cfunction_trampoline(lua_State* L, lua_CFunction f) { +#if SOL_IS_ON(SOL_PROPAGATE_EXCEPTIONS_I_) return f(L); #else @@ -117,7 +117,7 @@ namespace sol { catch (const std::exception& e) { call_exception_handler(L, optional(e), e.what()); } -#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) +#if SOL_IS_OFF(SOL_USE_LUAJIT_I_) // 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 @@ -131,61 +131,53 @@ namespace sol { template int static_trampoline(lua_State* L) { - return impl_static_trampoline(L, f); + return lua_cfunction_trampoline(L, f); } -#ifdef SOL_NOEXCEPT_FUNCTION_TYPE -#if 0 - // impossible: g++/clang++ choke as they think this function is ambiguous: - // to fix, wait for template and then switch on no-exceptness of the function - template - int static_trampoline(lua_State* L) noexcept { - return f(L); - } -#else +#if SOL_IS_ON(SOL_USE_NOEXCEPT_FUNCTION_TYPE_I_) template int static_trampoline_noexcept(lua_State* L) noexcept { return f(L); } -#endif // impossible - #else template int static_trampoline_noexcept(lua_State* L) noexcept { return f(L); } -#endif // noexcept lua_CFunction type +#endif template int trampoline(lua_State* L, Fx&& f, Args&&... args) { - if (meta::bind_traits>::is_noexcept) { + if constexpr (meta::bind_traits>::is_noexcept) { return f(L, std::forward(args)...); } -#if defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && !defined(SOL_LUAJIT) - return f(L, std::forward(args)...); + else { +#if SOL_IS_ON(SOL_PROPAGATE_EXCEPTIONS_I_) + return f(L, std::forward(args)...); #else - try { - return f(L, std::forward(args)...); - } - catch (const char* cs) { - call_exception_handler(L, optional(nullopt), string_view(cs)); - } - catch (const std::string& s) { - call_exception_handler(L, optional(nullopt), string_view(s.c_str(), s.size())); - } - catch (const std::exception& e) { - call_exception_handler(L, optional(e), e.what()); - } -#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 - catch (...) { - call_exception_handler(L, optional(nullopt), "caught (...) exception"); - } + try { + return f(L, std::forward(args)...); + } + catch (const char* cs) { + call_exception_handler(L, optional(nullopt), string_view(cs)); + } + catch (const std::string& s) { + call_exception_handler(L, optional(nullopt), string_view(s.c_str(), s.size())); + } + catch (const std::exception& e) { + call_exception_handler(L, optional(e), e.what()); + } +#if SOL_IS_OFF(SOL_USE_LUAJIT_I_) + // 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 + catch (...) { + call_exception_handler(L, optional(nullopt), "caught (...) exception"); + } #endif - return lua_error(L); + return lua_error(L); #endif + } } inline int c_trampoline(lua_State* L, lua_CFunction f) { @@ -193,29 +185,25 @@ namespace sol { } #endif // Exceptions vs. No Exceptions - template - inline int typed_static_trampoline_raw(std::true_type, lua_State* L) { - return static_trampoline_noexcept(L); - } - - template - inline int typed_static_trampoline_raw(std::false_type, lua_State* L) { - return static_trampoline(L); - } - template inline int typed_static_trampoline(lua_State* L) { - return typed_static_trampoline_raw(std::integral_constant::is_noexcept>(), L); + if constexpr (meta::bind_traits::is_noexcept) { + return static_trampoline_noexcept(L); + } + else { + return static_trampoline(L); + } } } // namespace detail inline void set_default_exception_handler(lua_State* L, exception_handler_function exf = &detail::default_exception_handler) { - static_assert(sizeof(void*) >= sizeof(exception_handler_function), "void* storage is too small to transport the exception handler: please file a bug on the issue tracker"); + static_assert(sizeof(void*) >= sizeof(exception_handler_function), + "void* storage is too small to transport the exception handler: please file a bug on the sol2 issue tracker to get this looked at!"); void* storage; std::memcpy(&storage, &exf, sizeof(exception_handler_function)); lua_pushlightuserdata(L, storage); lua_setglobal(L, detail::default_exception_handler_name()); } -} // sol +} // namespace sol #endif // SOL_TRAMPOLINE_HPP diff --git a/include/sol/unsafe_function_result.hpp b/include/sol/unsafe_function_result.hpp index 25afe5fc..d2fc1312 100644 --- a/include/sol/unsafe_function_result.hpp +++ b/include/sol/unsafe_function_result.hpp @@ -1,4 +1,4 @@ -// sol3 +// sol3 // The MIT License (MIT) @@ -50,20 +50,25 @@ namespace sol { typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; - unsafe_function_result() = default; - unsafe_function_result(lua_State* Ls, int idx = -1, int retnum = 0) - : L(Ls), index(idx), returncount(retnum) { + unsafe_function_result() noexcept = default; + unsafe_function_result(lua_State* Ls, int idx = -1, int retnum = 0) noexcept : L(Ls), index(idx), returncount(retnum) { } - unsafe_function_result(const unsafe_function_result&) = default; - unsafe_function_result& operator=(const unsafe_function_result&) = default; - unsafe_function_result(unsafe_function_result&& o) - : L(o.L), index(o.index), returncount(o.returncount) { + + + // We do not want anyone to copy these around willy-nilly + // Will likely break people, but also will probably get rid of quiet bugs that have + // been lurking. (E.g., Vanilla Lua will just quietly discard over-pops and under-pops: + // LuaJIT and other Lua engines will implode and segfault at random later times.) + unsafe_function_result(const unsafe_function_result&) = delete; + unsafe_function_result& operator=(const unsafe_function_result&) = delete; + + unsafe_function_result(unsafe_function_result&& o) noexcept : L(o.L), index(o.index), returncount(o.returncount) { // Must be manual, otherwise destructor will screw us // return count being 0 is enough to keep things clean // but will be thorough o.abandon(); } - unsafe_function_result& operator=(unsafe_function_result&& o) { + unsafe_function_result& operator=(unsafe_function_result&& o) noexcept { L = o.L; index = o.index; returncount = o.returncount; @@ -148,7 +153,7 @@ namespace sol { return returncount; }; void abandon() noexcept { - //L = nullptr; + // L = nullptr; index = 0; returncount = 0; } diff --git a/include/sol/version.hpp b/include/sol/version.hpp index 5e362049..8ca5dc81 100644 --- a/include/sol/version.hpp +++ b/include/sol/version.hpp @@ -68,6 +68,12 @@ #define SOL_COMPILER_VCXX_I_ SOL_OFF #endif +#if defined(__MINGW32__) + #define SOL_COMPILER_FRONTEND_MINGW_I_ SOL_ON +#else + #define SOL_COMPILER_FRONTEND_MINGW_I_ SOL_OFF +#endif + #if SIZE_MAX <= 0xFFFFULL #define SOL_PLATFORM_X16_I_ SOL_ON #define SOL_PLATFORM_X86_I_ SOL_OFF @@ -125,7 +131,7 @@ #define SOL_DEBUG_BUILD_I_ SOL_OFF #endif #else - #define SOL_DEBUG_BUILD_I_ SOL_OFF + #define SOL_DEBUG_BUILD_I_ SOL_DEFAULT_OFF #endif // We are in a debug mode of some sort #if defined(SOL_NO_EXCEPTIONS) @@ -147,7 +153,7 @@ #define SOL_EXCEPTIONS_I_ SOL_ON #endif #else - #define SOL_EXCEPTIONS_I_ SOL_ON + #define SOL_EXCEPTIONS_I_ SOL_DEFAULT_ON #endif @@ -170,7 +176,7 @@ #define SOL_RTTI_I_ SOL_ON #endif #else - #define SOL_EXCEPTIONS_I_ SOL_ON + #define SOL_RTTI_I_ SOL_DEFAULT_ON #endif #if defined(SOL_NO_THREAD_LOCAL) && (SOL_NO_THREAD_LOCAL != 0) @@ -182,7 +188,7 @@ #if defined(SOL_ALL_SAFETIES_ON) && (SOL_ALL_SAFETIES_ON != 0) #define SOL_ALL_SAFETIES_ON_I_ SOL_ON #else - #define SOL_ALL_SAFETIES_ON_I_ SOL_OFF + #define SOL_ALL_SAFETIES_ON_I_ SOL_DEFAULT_OFF #endif #if defined(SOL_SAFE_GETTER) && (SOL_SAFE_GETTER != 0) @@ -193,7 +199,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_GETTER_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_GETTER_I_ SOL_OFF + #define SOL_SAFE_GETTER_I_ SOL_DEFAULT_OFF #endif #endif @@ -205,7 +211,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_USERTYPE_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_USERTYPE_I_ SOL_OFF + #define SOL_SAFE_USERTYPE_I_ SOL_DEFAULT_OFF #endif #endif @@ -217,7 +223,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_REFERENCES_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_REFERENCES_I_ SOL_OFF + #define SOL_SAFE_REFERENCES_I_ SOL_DEFAULT_OFF #endif #endif @@ -230,7 +236,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_FUNCTION_OBJECTS_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_FUNCTION_OBJECTS_I_ SOL_OFF + #define SOL_SAFE_FUNCTION_OBJECTS_I_ SOL_DEFAULT_OFF #endif #endif @@ -242,7 +248,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_FUNCTION_CALLS_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_FUNCTION_CALLS_I_ SOL_OFF + #define SOL_SAFE_FUNCTION_CALLS_I_ SOL_DEFAULT_OFF #endif #endif @@ -254,7 +260,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_PROXIES_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_PROXIES_I_ SOL_OFF + #define SOL_SAFE_PROXIES_I_ SOL_DEFAULT_OFF #endif #endif @@ -266,7 +272,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_NUMERICS_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_NUMERICS_I_ SOL_OFF + #define SOL_SAFE_NUMERICS_I_ SOL_DEFAULT_OFF #endif #endif @@ -278,7 +284,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_STACK_CHECK_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_STACK_CHECK_I_ SOL_OFF + #define SOL_SAFE_STACK_CHECK_I_ SOL_DEFAULT_OFF #endif #endif @@ -288,10 +294,12 @@ #else #if SOL_IS_ON(SOL_ALL_SAFETIES_ON_I_) #define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_ON + #elif SOL_IS_ON(SOL_SAFE_NUMERICS_I_) + #define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_ON #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_DEFAULT_ON #else - #define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_OFF + #define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_DEFAULT_OFF #endif #endif @@ -302,14 +310,14 @@ #define SOL_STRINGS_ARE_NUMBERS_I_ SOL_OFF #endif #else - #define SOL_STRINGS_ARE_NUMBERS_I_ SOL_OFF + #define SOL_STRINGS_ARE_NUMBERS_I_ SOL_DEFAULT_OFF #endif #if defined(SOL_ENABLE_INTEROP) && (SOL_ENABLE_INTEROP != 0) \ || defined(SOL_USE_INTEROP) && (SOL_USE_INTEROP != 0) #define SOL_USE_INTEROP_I_ SOL_ON #else - #define SOL_USE_INTEROP_I_ SOL_OFF + #define SOL_USE_INTEROP_I_ SOL_DEFAULT_OFF #endif #if defined(SOL_NO_NIL) @@ -319,7 +327,7 @@ #define SOL_NIL_I_ SOL_ON #endif #elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || defined(__OBJC__) || defined(nil) - #define SOL_NIL_I_ SOL_OFF + #define SOL_NIL_I_ SOL_DEFAULT_OFF #else #define SOL_NIL_I_ SOL_DEFAULT_ON #endif @@ -413,8 +421,12 @@ #define SOL_FILE_ID_SIZE_I_ 2048 #endif -#if defined(SOL_PRINT_ERRORS) && (SOL_PRINT_ERRORS != 0) - #define SOL_PRINT_ERRORS_I_ SOL_ON +#if defined(SOL_PRINT_ERRORS) + #if (SOL_PRINT_ERRORS != 0) + #define SOL_PRINT_ERRORS_I_ SOL_ON + #else + #define SOL_PRINT_ERRORS_I_ SOL_OFF + #endif #else #if SOL_IS_ON(SOL_ALL_SAFETIES_ON_I_) #define SOL_PRINT_ERRORS_I_ SOL_ON @@ -526,6 +538,37 @@ #else #define SOL_USE_UNSAFE_BASE_LOOKUP_I_ SOL_OFF #endif + +#if defined(SOL_INSIDE_UNREAL) + #if (SOL_INSIDE_UNREAL != 0) + #define SOL_INSIDE_UNREAL_ENGINE_I_ SOL_ON + #else + #define SOL_INSIDE_UNREAL_ENGINE_I_ SOL_OFF + #endif +#else + #if defined(UE_BUILD_DEBUG) || defined(UE_BUILD_DEVELOPMENT) || defined(UE_BUILD_TEST) || defined(UE_BUILD_SHIPPING) || defined(UE_SERVER) + #define SOL_INSIDE_UNREAL_ENGINE_I_ SOL_ON + #else + #define SOL_INSIDE_UNREAL_ENGINE_I_ SOL_DEFAULT_OFF + #endif +#endif + +#if defined(SOL_NO_COMPAT) + #if (SOL_NO_COMPAT != 0) + #define SOL_USE_COMPATIBILITY_LAYER_I_ SOL_OFF + #else + #define SOL_USE_COMPATIBILITY_LAYER_I_ SOL_ON + #endif +#else + #define SOL_USE_COMPATIBILITY_LAYER_I_ SOL_DEFAULT_ON +#endif + +#if SOL_IS_ON(SOL_COMPILER_FRONTEND_MINGW_I_) && defined(__GNUC__) && (__GNUC__ < 6) + // MinGW is off its rocker in some places... + #define SOL_MINGW_CCTYPE_IS_POISONED_I_ SOL_ON +#else + #define SOL_MINGW_CCTYPE_IS_POISONED_I_ SOL_DEFAULT_OFF +#endif // clang-format on #endif // SOL_VERSION_HPP diff --git a/single/include/sol/config.hpp b/single/include/sol/config.hpp index 563d8cd2..eef2cc89 100644 --- a/single/include/sol/config.hpp +++ b/single/include/sol/config.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 2020-09-09 00:46:22.609996 UTC -// This header was generated with sol v3.2.1 (revision e4f588d) +// Generated 2020-09-26 10:44:02.641191 UTC +// This header was generated with sol v3.2.1 (revision e89b6ac) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_CONFIG_HPP diff --git a/single/include/sol/forward.hpp b/single/include/sol/forward.hpp index c707bb83..0e0705cf 100644 --- a/single/include/sol/forward.hpp +++ b/single/include/sol/forward.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 2020-09-09 00:46:22.606997 UTC -// This header was generated with sol v3.2.1 (revision e4f588d) +// Generated 2020-09-26 10:44:02.626193 UTC +// This header was generated with sol v3.2.1 (revision e89b6ac) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP @@ -76,6 +76,12 @@ #define SOL_COMPILER_VCXX_I_ SOL_OFF #endif +#if defined(__MINGW32__) + #define SOL_COMPILER_FRONTEND_MINGW_I_ SOL_ON +#else + #define SOL_COMPILER_FRONTEND_MINGW_I_ SOL_OFF +#endif + #if SIZE_MAX <= 0xFFFFULL #define SOL_PLATFORM_X16_I_ SOL_ON #define SOL_PLATFORM_X86_I_ SOL_OFF @@ -132,7 +138,7 @@ #define SOL_DEBUG_BUILD_I_ SOL_OFF #endif #else - #define SOL_DEBUG_BUILD_I_ SOL_OFF + #define SOL_DEBUG_BUILD_I_ SOL_DEFAULT_OFF #endif // We are in a debug mode of some sort #if defined(SOL_NO_EXCEPTIONS) @@ -154,7 +160,7 @@ #define SOL_EXCEPTIONS_I_ SOL_ON #endif #else - #define SOL_EXCEPTIONS_I_ SOL_ON + #define SOL_EXCEPTIONS_I_ SOL_DEFAULT_ON #endif #if defined(SOL_NO_RTTI) @@ -176,7 +182,7 @@ #define SOL_RTTI_I_ SOL_ON #endif #else - #define SOL_EXCEPTIONS_I_ SOL_ON + #define SOL_RTTI_I_ SOL_DEFAULT_ON #endif #if defined(SOL_NO_THREAD_LOCAL) && (SOL_NO_THREAD_LOCAL != 0) @@ -188,7 +194,7 @@ #if defined(SOL_ALL_SAFETIES_ON) && (SOL_ALL_SAFETIES_ON != 0) #define SOL_ALL_SAFETIES_ON_I_ SOL_ON #else - #define SOL_ALL_SAFETIES_ON_I_ SOL_OFF + #define SOL_ALL_SAFETIES_ON_I_ SOL_DEFAULT_OFF #endif #if defined(SOL_SAFE_GETTER) && (SOL_SAFE_GETTER != 0) @@ -199,7 +205,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_GETTER_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_GETTER_I_ SOL_OFF + #define SOL_SAFE_GETTER_I_ SOL_DEFAULT_OFF #endif #endif @@ -211,7 +217,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_USERTYPE_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_USERTYPE_I_ SOL_OFF + #define SOL_SAFE_USERTYPE_I_ SOL_DEFAULT_OFF #endif #endif @@ -223,7 +229,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_REFERENCES_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_REFERENCES_I_ SOL_OFF + #define SOL_SAFE_REFERENCES_I_ SOL_DEFAULT_OFF #endif #endif @@ -236,7 +242,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_FUNCTION_OBJECTS_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_FUNCTION_OBJECTS_I_ SOL_OFF + #define SOL_SAFE_FUNCTION_OBJECTS_I_ SOL_DEFAULT_OFF #endif #endif @@ -248,7 +254,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_FUNCTION_CALLS_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_FUNCTION_CALLS_I_ SOL_OFF + #define SOL_SAFE_FUNCTION_CALLS_I_ SOL_DEFAULT_OFF #endif #endif @@ -260,7 +266,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_PROXIES_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_PROXIES_I_ SOL_OFF + #define SOL_SAFE_PROXIES_I_ SOL_DEFAULT_OFF #endif #endif @@ -272,7 +278,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_NUMERICS_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_NUMERICS_I_ SOL_OFF + #define SOL_SAFE_NUMERICS_I_ SOL_DEFAULT_OFF #endif #endif @@ -284,7 +290,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_STACK_CHECK_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_STACK_CHECK_I_ SOL_OFF + #define SOL_SAFE_STACK_CHECK_I_ SOL_DEFAULT_OFF #endif #endif @@ -294,10 +300,12 @@ #else #if SOL_IS_ON(SOL_ALL_SAFETIES_ON_I_) #define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_ON + #elif SOL_IS_ON(SOL_SAFE_NUMERICS_I_) + #define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_ON #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_DEFAULT_ON #else - #define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_OFF + #define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_DEFAULT_OFF #endif #endif @@ -308,14 +316,14 @@ #define SOL_STRINGS_ARE_NUMBERS_I_ SOL_OFF #endif #else - #define SOL_STRINGS_ARE_NUMBERS_I_ SOL_OFF + #define SOL_STRINGS_ARE_NUMBERS_I_ SOL_DEFAULT_OFF #endif #if defined(SOL_ENABLE_INTEROP) && (SOL_ENABLE_INTEROP != 0) \ || defined(SOL_USE_INTEROP) && (SOL_USE_INTEROP != 0) #define SOL_USE_INTEROP_I_ SOL_ON #else - #define SOL_USE_INTEROP_I_ SOL_OFF + #define SOL_USE_INTEROP_I_ SOL_DEFAULT_OFF #endif #if defined(SOL_NO_NIL) @@ -325,7 +333,7 @@ #define SOL_NIL_I_ SOL_ON #endif #elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || defined(__OBJC__) || defined(nil) - #define SOL_NIL_I_ SOL_OFF + #define SOL_NIL_I_ SOL_DEFAULT_OFF #else #define SOL_NIL_I_ SOL_DEFAULT_ON #endif @@ -419,8 +427,12 @@ #define SOL_FILE_ID_SIZE_I_ 2048 #endif -#if defined(SOL_PRINT_ERRORS) && (SOL_PRINT_ERRORS != 0) - #define SOL_PRINT_ERRORS_I_ SOL_ON +#if defined(SOL_PRINT_ERRORS) + #if (SOL_PRINT_ERRORS != 0) + #define SOL_PRINT_ERRORS_I_ SOL_ON + #else + #define SOL_PRINT_ERRORS_I_ SOL_OFF + #endif #else #if SOL_IS_ON(SOL_ALL_SAFETIES_ON_I_) #define SOL_PRINT_ERRORS_I_ SOL_ON @@ -533,6 +545,37 @@ #define SOL_USE_UNSAFE_BASE_LOOKUP_I_ SOL_OFF #endif +#if defined(SOL_INSIDE_UNREAL) + #if (SOL_INSIDE_UNREAL != 0) + #define SOL_INSIDE_UNREAL_ENGINE_I_ SOL_ON + #else + #define SOL_INSIDE_UNREAL_ENGINE_I_ SOL_OFF + #endif +#else + #if defined(UE_BUILD_DEBUG) || defined(UE_BUILD_DEVELOPMENT) || defined(UE_BUILD_TEST) || defined(UE_BUILD_SHIPPING) || defined(UE_SERVER) + #define SOL_INSIDE_UNREAL_ENGINE_I_ SOL_ON + #else + #define SOL_INSIDE_UNREAL_ENGINE_I_ SOL_DEFAULT_OFF + #endif +#endif + +#if defined(SOL_NO_COMPAT) + #if (SOL_NO_COMPAT != 0) + #define SOL_USE_COMPATIBILITY_LAYER_I_ SOL_OFF + #else + #define SOL_USE_COMPATIBILITY_LAYER_I_ SOL_ON + #endif +#else + #define SOL_USE_COMPATIBILITY_LAYER_I_ SOL_DEFAULT_ON +#endif + +#if SOL_IS_ON(SOL_COMPILER_FRONTEND_MINGW_I_) && defined(__GNUC__) && (__GNUC__ < 6) + // MinGW is off its rocker in some places... + #define SOL_MINGW_CCTYPE_IS_POISONED_I_ SOL_ON +#else + #define SOL_MINGW_CCTYPE_IS_POISONED_I_ SOL_DEFAULT_OFF +#endif + // end of sol/version.hpp #include diff --git a/single/include/sol/sol.hpp b/single/include/sol/sol.hpp index cfe15dac..dc96db1e 100644 --- a/single/include/sol/sol.hpp +++ b/single/include/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 2020-09-09 00:46:22.298307 UTC -// This header was generated with sol v3.2.1 (revision e4f588d) +// Generated 2020-09-26 10:44:01.822191 UTC +// This header was generated with sol v3.2.1 (revision e89b6ac) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -32,32 +32,6 @@ #ifndef SOL_HPP #define SOL_HPP -#if defined(UE_BUILD_DEBUG) || defined(UE_BUILD_DEVELOPMENT) || defined(UE_BUILD_TEST) || defined(UE_BUILD_SHIPPING) || defined(UE_SERVER) -#define SOL_INSIDE_UNREAL -#ifdef check -#pragma push_macro("check") -#undef check -#endif -#endif // Unreal Engine 4 Bullshit - -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wshadow" -#pragma GCC diagnostic ignored "-Wconversion" -#if __GNUC__ > 6 -#pragma GCC diagnostic ignored "-Wnoexcept-type" -#endif -#elif defined(__clang__) -#elif defined _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4505) // unreferenced local function has been removed GEE THANKS -#endif // clang++ vs. g++ vs. VC++ - -// beginning of sol/forward.hpp - -#ifndef SOL_FORWARD_HPP -#define SOL_FORWARD_HPP - // beginning of sol/version.hpp #include @@ -102,6 +76,12 @@ #define SOL_COMPILER_VCXX_I_ SOL_OFF #endif +#if defined(__MINGW32__) + #define SOL_COMPILER_FRONTEND_MINGW_I_ SOL_ON +#else + #define SOL_COMPILER_FRONTEND_MINGW_I_ SOL_OFF +#endif + #if SIZE_MAX <= 0xFFFFULL #define SOL_PLATFORM_X16_I_ SOL_ON #define SOL_PLATFORM_X86_I_ SOL_OFF @@ -158,7 +138,7 @@ #define SOL_DEBUG_BUILD_I_ SOL_OFF #endif #else - #define SOL_DEBUG_BUILD_I_ SOL_OFF + #define SOL_DEBUG_BUILD_I_ SOL_DEFAULT_OFF #endif // We are in a debug mode of some sort #if defined(SOL_NO_EXCEPTIONS) @@ -180,7 +160,7 @@ #define SOL_EXCEPTIONS_I_ SOL_ON #endif #else - #define SOL_EXCEPTIONS_I_ SOL_ON + #define SOL_EXCEPTIONS_I_ SOL_DEFAULT_ON #endif #if defined(SOL_NO_RTTI) @@ -202,7 +182,7 @@ #define SOL_RTTI_I_ SOL_ON #endif #else - #define SOL_EXCEPTIONS_I_ SOL_ON + #define SOL_RTTI_I_ SOL_DEFAULT_ON #endif #if defined(SOL_NO_THREAD_LOCAL) && (SOL_NO_THREAD_LOCAL != 0) @@ -214,7 +194,7 @@ #if defined(SOL_ALL_SAFETIES_ON) && (SOL_ALL_SAFETIES_ON != 0) #define SOL_ALL_SAFETIES_ON_I_ SOL_ON #else - #define SOL_ALL_SAFETIES_ON_I_ SOL_OFF + #define SOL_ALL_SAFETIES_ON_I_ SOL_DEFAULT_OFF #endif #if defined(SOL_SAFE_GETTER) && (SOL_SAFE_GETTER != 0) @@ -225,7 +205,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_GETTER_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_GETTER_I_ SOL_OFF + #define SOL_SAFE_GETTER_I_ SOL_DEFAULT_OFF #endif #endif @@ -237,7 +217,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_USERTYPE_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_USERTYPE_I_ SOL_OFF + #define SOL_SAFE_USERTYPE_I_ SOL_DEFAULT_OFF #endif #endif @@ -249,7 +229,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_REFERENCES_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_REFERENCES_I_ SOL_OFF + #define SOL_SAFE_REFERENCES_I_ SOL_DEFAULT_OFF #endif #endif @@ -262,7 +242,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_FUNCTION_OBJECTS_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_FUNCTION_OBJECTS_I_ SOL_OFF + #define SOL_SAFE_FUNCTION_OBJECTS_I_ SOL_DEFAULT_OFF #endif #endif @@ -274,7 +254,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_FUNCTION_CALLS_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_FUNCTION_CALLS_I_ SOL_OFF + #define SOL_SAFE_FUNCTION_CALLS_I_ SOL_DEFAULT_OFF #endif #endif @@ -286,7 +266,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_PROXIES_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_PROXIES_I_ SOL_OFF + #define SOL_SAFE_PROXIES_I_ SOL_DEFAULT_OFF #endif #endif @@ -298,7 +278,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_NUMERICS_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_NUMERICS_I_ SOL_OFF + #define SOL_SAFE_NUMERICS_I_ SOL_DEFAULT_OFF #endif #endif @@ -310,7 +290,7 @@ #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_SAFE_STACK_CHECK_I_ SOL_DEFAULT_ON #else - #define SOL_SAFE_STACK_CHECK_I_ SOL_OFF + #define SOL_SAFE_STACK_CHECK_I_ SOL_DEFAULT_OFF #endif #endif @@ -320,10 +300,12 @@ #else #if SOL_IS_ON(SOL_ALL_SAFETIES_ON_I_) #define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_ON + #elif SOL_IS_ON(SOL_SAFE_NUMERICS_I_) + #define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_ON #elif SOL_IS_ON(SOL_DEBUG_BUILD_I_) #define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_DEFAULT_ON #else - #define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_OFF + #define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_DEFAULT_OFF #endif #endif @@ -334,14 +316,14 @@ #define SOL_STRINGS_ARE_NUMBERS_I_ SOL_OFF #endif #else - #define SOL_STRINGS_ARE_NUMBERS_I_ SOL_OFF + #define SOL_STRINGS_ARE_NUMBERS_I_ SOL_DEFAULT_OFF #endif #if defined(SOL_ENABLE_INTEROP) && (SOL_ENABLE_INTEROP != 0) \ || defined(SOL_USE_INTEROP) && (SOL_USE_INTEROP != 0) #define SOL_USE_INTEROP_I_ SOL_ON #else - #define SOL_USE_INTEROP_I_ SOL_OFF + #define SOL_USE_INTEROP_I_ SOL_DEFAULT_OFF #endif #if defined(SOL_NO_NIL) @@ -351,7 +333,7 @@ #define SOL_NIL_I_ SOL_ON #endif #elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || defined(__OBJC__) || defined(nil) - #define SOL_NIL_I_ SOL_OFF + #define SOL_NIL_I_ SOL_DEFAULT_OFF #else #define SOL_NIL_I_ SOL_DEFAULT_ON #endif @@ -445,8 +427,12 @@ #define SOL_FILE_ID_SIZE_I_ 2048 #endif -#if defined(SOL_PRINT_ERRORS) && (SOL_PRINT_ERRORS != 0) - #define SOL_PRINT_ERRORS_I_ SOL_ON +#if defined(SOL_PRINT_ERRORS) + #if (SOL_PRINT_ERRORS != 0) + #define SOL_PRINT_ERRORS_I_ SOL_ON + #else + #define SOL_PRINT_ERRORS_I_ SOL_OFF + #endif #else #if SOL_IS_ON(SOL_ALL_SAFETIES_ON_I_) #define SOL_PRINT_ERRORS_I_ SOL_ON @@ -559,8 +545,64 @@ #define SOL_USE_UNSAFE_BASE_LOOKUP_I_ SOL_OFF #endif +#if defined(SOL_INSIDE_UNREAL) + #if (SOL_INSIDE_UNREAL != 0) + #define SOL_INSIDE_UNREAL_ENGINE_I_ SOL_ON + #else + #define SOL_INSIDE_UNREAL_ENGINE_I_ SOL_OFF + #endif +#else + #if defined(UE_BUILD_DEBUG) || defined(UE_BUILD_DEVELOPMENT) || defined(UE_BUILD_TEST) || defined(UE_BUILD_SHIPPING) || defined(UE_SERVER) + #define SOL_INSIDE_UNREAL_ENGINE_I_ SOL_ON + #else + #define SOL_INSIDE_UNREAL_ENGINE_I_ SOL_DEFAULT_OFF + #endif +#endif + +#if defined(SOL_NO_COMPAT) + #if (SOL_NO_COMPAT != 0) + #define SOL_USE_COMPATIBILITY_LAYER_I_ SOL_OFF + #else + #define SOL_USE_COMPATIBILITY_LAYER_I_ SOL_ON + #endif +#else + #define SOL_USE_COMPATIBILITY_LAYER_I_ SOL_DEFAULT_ON +#endif + +#if SOL_IS_ON(SOL_COMPILER_FRONTEND_MINGW_I_) && defined(__GNUC__) && (__GNUC__ < 6) + // MinGW is off its rocker in some places... + #define SOL_MINGW_CCTYPE_IS_POISONED_I_ SOL_ON +#else + #define SOL_MINGW_CCTYPE_IS_POISONED_I_ SOL_DEFAULT_OFF +#endif + // end of sol/version.hpp +#if SOL_IS_ON(SOL_INSIDE_UNREAL_ENGINE_I_) +#ifdef check +#pragma push_macro("check") +#undef check +#endif +#endif // Unreal Engine 4 Bullshit + +#if SOL_IS_ON(SOL_COMPILER_GCC_I_) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" +#pragma GCC diagnostic ignored "-Wconversion" +#if __GNUC__ > 6 +#pragma GCC diagnostic ignored "-Wnoexcept-type" +#endif +#elif SOL_IS_ON(SOL_COMPILER_CLANG_I_) +#elif SOL_IS_ON(SOL_COMPILER_VCXX_I_) +#pragma warning(push) +#pragma warning(disable : 4505) // unreferenced local function has been removed GEE THANKS +#endif // clang++ vs. g++ vs. VC++ + +// beginning of sol/forward.hpp + +#ifndef SOL_FORWARD_HPP +#define SOL_FORWARD_HPP + #include #include #include @@ -2285,7 +2327,7 @@ namespace sol { #elif defined(LUAJIT_VERSION) #define SOL_USE_LUAJIT_I_ SOL_OFF #else - #define SOL_USE_LUAJIT_I_ SOL_OFF + #define SOL_USE_LUAJIT_I_ SOL_DEFAULT_OFF #endif // luajit #if SOL_IS_ON(SOL_USE_CXX_LUAJIT_I_) @@ -2305,9 +2347,9 @@ namespace sol { #endif #if defined(MOONJIT_VERSION) - #define SOL_MOONJIT_I_ SOL_ON + #define SOL_USE_MOONJIT_I_ SOL_ON #else - #define SOL_MOONJIT_I_ SOL_OFF + #define SOL_USE_MOONJIT_I_ SOL_OFF #endif #if !defined(SOL_LUA_VERSION) @@ -2330,10 +2372,18 @@ namespace sol { #define SOL_LUA_VESION_I_ 504 #endif -#if defined(SOL_EXCEPTIONS_ALWAYS_UNSAFE) && (SOL_EXCEPTIONS_ALWAYS_UNSAFE != 0) - #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_OFF -#elif defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && (SOL_EXCEPTIONS_SAFE_PROPAGATION != 0) - #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_ON +#if defined(SOL_EXCEPTIONS_ALWAYS_UNSAFE) + #if (SOL_EXCEPTIONS_ALWAYS_UNSAFE != 0) + #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_OFF + #else + #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_ON + #endif +#elif defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) + #if (SOL_EXCEPTIONS_SAFE_PROPAGATION != 0) + #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_ON + #else + #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_OFF + #endif #elif SOL_LUAJIT_VERSION_I_ >= 20100 // LuaJIT 2.1.0-beta3 and better have exception support locked in for all platforms (mostly) #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_DEFAULT_ON @@ -2348,12 +2398,40 @@ namespace sol { // otherwise, there is no exception safety for // shoving exceptions through Lua and errors should // always be serialized - #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_OFF + #define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_DEFAULT_OFF #endif // LuaJIT beta 02.01.00 have better exception handling on all platforms since beta3 +#if defined(SOL_LUAJIT_USE_EXCEPTION_TRAMPOLINE) + #if (SOL_LUAJIT_USE_EXCEPTION_TRAMPOLINE != 0) + #define SOL_USE_LUAJIT_EXCEPTION_TRAMPOLINE_I_ SOL_ON + #else + #define SOL_USE_LUAJIT_EXCEPTION_TRAMPOLINE_I_ SOL_OFF + #endif +#else + #if SOL_IS_OFF(SOL_PROPAGATE_EXCEPTIONS_I_) && SOL_IS_ON(SOL_USE_LUAJIT_I_) + #define SOL_USE_LUAJIT_EXCEPTION_TRAMPOLINE_I_ SOL_ON + #else + #define SOL_USE_LUAJIT_EXCEPTION_TRAMPOLINE_I_ SOL_DEFAULT_OFF + #endif +#endif + +#if defined(SOL_LUAL_STREAM_HAS_CLOSE_FUNCTION) + #if (SOL_LUAL_STREAM_HAS_CLOSE_FUNCTION != 0) + #define SOL_LUAL_STREAM_USE_CLOSE_FUNCTION_I_ SOL_ON + #else + #define SOL_LUAL_STREAM_USE_CLOSE_FUNCTION_I_ SOL_OFF + #endif +#else + #if SOL_IS_OFF(SOL_USE_LUAJIT_I_) && (SOL_LUA_VERSION > 501) + #define SOL_LUAL_STREAM_USE_CLOSE_FUNCTION_I_ SOL_ON + #else + #define SOL_LUAL_STREAM_USE_CLOSE_FUNCTION_I_ SOL_DEFAULT_OFF + #endif +#endif + // end of sol/compatibility/lua_version.hpp -#if !defined(SOL_NO_COMPAT) || !(SOL_NO_COMPAT) +#if SOL_IS_ON(SOL_USE_COMPATIBILITY_LAYER_I_) #if SOL_IS_ON(SOL_USE_CXX_LUA_I_) || SOL_IS_ON(SOL_USE_CXX_LUAJIT_I_) #ifndef COMPAT53_LUA_CPP @@ -3651,7 +3729,7 @@ extern "C" { #endif // NOT_KEPLER_PROJECT_COMPAT54_H_// end of sol/compatibility/compat-5.4.h -#endif // SOL_NO_COMPAT +#endif // end of sol/compatibility.hpp @@ -7819,10 +7897,10 @@ namespace sol { // must push a single object to be the error object // NOTE: the VAST MAJORITY of all Lua libraries -- C or otherwise -- expect a string for the type of error // break this convention at your own risk - using exception_handler_function = int(*)(lua_State*, optional, string_view); + using exception_handler_function = int (*)(lua_State*, optional, string_view); namespace detail { - inline const char(&default_exception_handler_name())[11]{ + inline const char (&default_exception_handler_name())[11] { static const char name[11] = "sol.\xE2\x98\xA2\xE2\x98\xA2"; return name; } @@ -7854,13 +7932,13 @@ namespace sol { return exfunc(L, std::move(maybe_ex), std::move(what)); } -#ifdef SOL_NO_EXCEPTIONS +#if SOL_IS_OFF(SOL_EXCEPTIONS_I_) template int static_trampoline(lua_State* L) noexcept { return f(L); } -#ifdef SOL_NOEXCEPT_FUNCTION_TYPE +#if SOL_IS_ON(SOL_USE_NOEXCEPT_FUNCTION_TYPE_I_) template int static_trampoline_noexcept(lua_State* L) noexcept { return f(L); @@ -7882,8 +7960,8 @@ namespace sol { } #else - inline int impl_static_trampoline(lua_State* L, lua_CFunction f) { -#if defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && !defined(SOL_LUAJIT) + inline int lua_cfunction_trampoline(lua_State* L, lua_CFunction f) { +#if SOL_IS_ON(SOL_PROPAGATE_EXCEPTIONS_I_) return f(L); #else @@ -7899,7 +7977,7 @@ namespace sol { catch (const std::exception& e) { call_exception_handler(L, optional(e), e.what()); } -#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) +#if SOL_IS_OFF(SOL_USE_LUAJIT_I_) // 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 @@ -7913,61 +7991,53 @@ namespace sol { template int static_trampoline(lua_State* L) { - return impl_static_trampoline(L, f); + return lua_cfunction_trampoline(L, f); } -#ifdef SOL_NOEXCEPT_FUNCTION_TYPE -#if 0 - // impossible: g++/clang++ choke as they think this function is ambiguous: - // to fix, wait for template and then switch on no-exceptness of the function - template - int static_trampoline(lua_State* L) noexcept { - return f(L); - } -#else +#if SOL_IS_ON(SOL_USE_NOEXCEPT_FUNCTION_TYPE_I_) template int static_trampoline_noexcept(lua_State* L) noexcept { return f(L); } -#endif // impossible - #else template int static_trampoline_noexcept(lua_State* L) noexcept { return f(L); } -#endif // noexcept lua_CFunction type +#endif template int trampoline(lua_State* L, Fx&& f, Args&&... args) { - if (meta::bind_traits>::is_noexcept) { + if constexpr (meta::bind_traits>::is_noexcept) { return f(L, std::forward(args)...); } -#if defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && !defined(SOL_LUAJIT) - return f(L, std::forward(args)...); + else { +#if SOL_IS_ON(SOL_PROPAGATE_EXCEPTIONS_I_) + return f(L, std::forward(args)...); #else - try { - return f(L, std::forward(args)...); - } - catch (const char* cs) { - call_exception_handler(L, optional(nullopt), string_view(cs)); - } - catch (const std::string& s) { - call_exception_handler(L, optional(nullopt), string_view(s.c_str(), s.size())); - } - catch (const std::exception& e) { - call_exception_handler(L, optional(e), e.what()); - } -#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 - catch (...) { - call_exception_handler(L, optional(nullopt), "caught (...) exception"); - } + try { + return f(L, std::forward(args)...); + } + catch (const char* cs) { + call_exception_handler(L, optional(nullopt), string_view(cs)); + } + catch (const std::string& s) { + call_exception_handler(L, optional(nullopt), string_view(s.c_str(), s.size())); + } + catch (const std::exception& e) { + call_exception_handler(L, optional(e), e.what()); + } +#if SOL_IS_OFF(SOL_USE_LUAJIT_I_) + // 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 + catch (...) { + call_exception_handler(L, optional(nullopt), "caught (...) exception"); + } #endif - return lua_error(L); + return lua_error(L); #endif + } } inline int c_trampoline(lua_State* L, lua_CFunction f) { @@ -7975,30 +8045,26 @@ namespace sol { } #endif // Exceptions vs. No Exceptions - template - inline int typed_static_trampoline_raw(std::true_type, lua_State* L) { - return static_trampoline_noexcept(L); - } - - template - inline int typed_static_trampoline_raw(std::false_type, lua_State* L) { - return static_trampoline(L); - } - template inline int typed_static_trampoline(lua_State* L) { - return typed_static_trampoline_raw(std::integral_constant::is_noexcept>(), L); + if constexpr (meta::bind_traits::is_noexcept) { + return static_trampoline_noexcept(L); + } + else { + return static_trampoline(L); + } } } // namespace detail inline void set_default_exception_handler(lua_State* L, exception_handler_function exf = &detail::default_exception_handler) { - static_assert(sizeof(void*) >= sizeof(exception_handler_function), "void* storage is too small to transport the exception handler: please file a bug on the issue tracker"); + static_assert(sizeof(void*) >= sizeof(exception_handler_function), + "void* storage is too small to transport the exception handler: please file a bug on the sol2 issue tracker to get this looked at!"); void* storage; std::memcpy(&storage, &exf, sizeof(exception_handler_function)); lua_pushlightuserdata(L, storage); lua_setglobal(L, detail::default_exception_handler_name()); } -} // sol +} // namespace sol // end of sol/trampoline.hpp @@ -8013,16 +8079,15 @@ namespace sol { #include #include #include -#if defined(__GNUC__) && defined(__MINGW32__) && (__GNUC__ < 6) +#if SOL_IS_ON(SOL_MINGW_CCTYPE_IS_POISONED_I_) extern "C" { #include } #endif // MinGW is on some stuff #include -namespace sol { -namespace detail { - inline constexpr std::array removals{ { "{anonymous}", +namespace sol { namespace detail { + inline constexpr std::array removals { { "{anonymous}", "(anonymous namespace)", "public:", "private:", @@ -8032,7 +8097,7 @@ namespace detail { "`anonymous-namespace'", "`anonymous namespace'" } }; -#if defined(__GNUC__) || defined(__clang__) +#if SOL_IS_ON(SOL_COMPILER_GCC_I_) || SOL_IS_ON(SOL_COMPILER_CLANG_I_) inline std::string ctti_get_type_name_from_sig(std::string name) { // cardinal sins from MINGW using namespace std; @@ -8070,7 +8135,7 @@ namespace detail { inline std::string ctti_get_type_name() { return ctti_get_type_name_from_sig(__PRETTY_FUNCTION__); } -#elif defined(_MSC_VER) +#elif SOL_IS_ON(SOL_COMPILER_VCXX_I_) inline std::string ctti_get_type_name_from_sig(std::string name) { std::size_t start = name.find("get_type_name"); if (start == std::string::npos) @@ -8119,7 +8184,9 @@ namespace detail { inline std::string short_demangle_from_type_name(std::string realname) { // This isn't the most complete but it'll do for now...? - static const std::array ops = {{"operator<", "operator<<", "operator<<=", "operator<=", "operator>", "operator>>", "operator>>=", "operator>=", "operator->", "operator->*"}}; + static const std::array ops = { + { "operator<", "operator<<", "operator<<=", "operator<=", "operator>", "operator>>", "operator>>=", "operator>=", "operator->", "operator->*" } + }; int level = 0; std::ptrdiff_t idx = 0; for (idx = static_cast(realname.empty() ? 0 : realname.size() - 1); idx > 0; --idx) { @@ -8170,8 +8237,7 @@ namespace detail { static const std::string d = short_demangle_once(); return d; } -} -} // namespace sol::detail +}} // namespace sol::detail // end of sol/demangle.hpp @@ -8876,8 +8942,7 @@ namespace sol { lua_State* L; int index; int count; - push_popper_at(lua_State* luastate, int index = -1, int count = 1) - : L(luastate), index(index), count(count) { + push_popper_at(lua_State* luastate, int index = -1, int count = 1) : L(luastate), index(index), count(count) { } ~push_popper_at() { remove(L, index, count); @@ -8888,8 +8953,7 @@ namespace sol { struct push_popper_n { lua_State* L; int t; - push_popper_n(lua_State* luastate, int x) - : L(luastate), t(x) { + push_popper_n(lua_State* luastate, int x) : L(luastate), t(x) { } push_popper_n(const push_popper_n&) = delete; push_popper_n(push_popper_n&&) = default; @@ -8899,7 +8963,7 @@ namespace sol { lua_pop(L, t); } }; - + template <> struct push_popper_n { push_popper_n(lua_State*, int) { @@ -8912,9 +8976,7 @@ namespace sol { T t; int idx; - push_popper(T x) - : t(x), idx(lua_absindex(t.lua_state(), -t.push())) { - + push_popper(T x) : t(x), idx(lua_absindex(t.lua_state(), -t.push())) { } int index_of(const Tu&) { @@ -8940,11 +9002,11 @@ namespace sol { ~push_popper() { } }; - + template struct push_popper>>> { using Tu = meta::unqualified_t; - + push_popper(T) { } @@ -8967,7 +9029,7 @@ namespace sol { lua_State* L = x.lua_state(); return push_popper_at(L, lua_absindex(L, -c), c); } - + template push_popper_n pop_n(lua_State* L, int x) { return push_popper_n(L, x); @@ -8975,7 +9037,7 @@ namespace sol { } // namespace stack inline lua_State* main_thread(lua_State* L, lua_State* backup_if_unsupported = nullptr) { -#if SOL_LUA_VERSION < 502 +#if SOL_LUA_VESION_I_ < 502 if (L == nullptr) return backup_if_unsupported; lua_getglobal(L, detail::default_main_thread_name()); @@ -9043,7 +9105,7 @@ namespace sol { } protected: - int stack_index () const noexcept { + int stack_index() const noexcept { return -1; } @@ -9127,8 +9189,7 @@ namespace sol { stateless_reference(const stateless_reference& o) noexcept = delete; stateless_reference& operator=(const stateless_reference& r) noexcept = delete; - stateless_reference(stateless_reference&& o) noexcept - : ref(o.ref) { + stateless_reference(stateless_reference&& o) noexcept : ref(o.ref) { o.ref = LUA_NOREF; } @@ -9244,8 +9305,7 @@ namespace sol { : basic_reference(detail::pick_main_thread(L, L), detail::global_, detail::global_) { } - basic_reference(lua_State* L, detail::global_tag, detail::global_tag) noexcept - : stateless_reference(L, detail::global_), luastate(L) { + basic_reference(lua_State* L, detail::global_tag, detail::global_tag) noexcept : stateless_reference(L, detail::global_), luastate(L) { } basic_reference(lua_State* oL, const basic_reference& o) noexcept : stateless_reference(oL, o), luastate(oL) { @@ -9265,18 +9325,14 @@ namespace sol { public: basic_reference() noexcept = default; - basic_reference(lua_nil_t) noexcept - : basic_reference() { + basic_reference(lua_nil_t) noexcept : basic_reference() { } - basic_reference(const stack_reference& r) noexcept - : basic_reference(r.lua_state(), r.stack_index()) { + basic_reference(const stack_reference& r) noexcept : basic_reference(r.lua_state(), r.stack_index()) { } - basic_reference(stack_reference&& r) noexcept - : basic_reference(r.lua_state(), r.stack_index()) { + basic_reference(stack_reference&& r) noexcept : basic_reference(r.lua_state(), r.stack_index()) { } template - basic_reference(lua_State* L, const basic_reference& r) noexcept - : luastate(detail::pick_main_thread(L, L)) { + basic_reference(lua_State* L, const basic_reference& r) noexcept : luastate(detail::pick_main_thread(L, L)) { if (r.ref == LUA_REFNIL) { ref = LUA_REFNIL; return; @@ -9294,8 +9350,7 @@ namespace sol { } template - basic_reference(lua_State* L, basic_reference&& r) noexcept - : luastate(detail::pick_main_thread(L, L)) { + basic_reference(lua_State* L, basic_reference&& r) noexcept : luastate(detail::pick_main_thread(L, L)) { if (r.ref == LUA_REFNIL) { ref = LUA_REFNIL; return; @@ -9314,8 +9369,7 @@ namespace sol { r.luastate = nullptr; } - basic_reference(lua_State* L, const stack_reference& r) noexcept - : luastate(detail::pick_main_thread(L, L)) { + basic_reference(lua_State* L, const stack_reference& r) noexcept : luastate(detail::pick_main_thread(L, L)) { if (lua_state() == nullptr || r.lua_state() == nullptr || r.get_type() == type::none) { ref = LUA_NOREF; return; @@ -9330,8 +9384,7 @@ namespace sol { r.push(lua_state()); ref = luaL_ref(lua_state(), LUA_REGISTRYINDEX); } - basic_reference(lua_State* L, int index = -1) noexcept - : luastate(detail::pick_main_thread(L, L)) { + basic_reference(lua_State* L, int index = -1) noexcept : luastate(detail::pick_main_thread(L, L)) { // use L to stick with that state's execution stack #if SOL_IS_ON(SOL_SAFE_STACK_CHECK_I_) luaL_checkstack(L, 1, "not enough Lua stack space to push this reference value"); @@ -9339,13 +9392,11 @@ namespace sol { lua_pushvalue(L, index); ref = luaL_ref(L, LUA_REGISTRYINDEX); } - basic_reference(lua_State* L, ref_index index) noexcept - : luastate(detail::pick_main_thread(L, L)) { + basic_reference(lua_State* L, ref_index index) noexcept : luastate(detail::pick_main_thread(L, L)) { lua_rawgeti(lua_state(), LUA_REGISTRYINDEX, index.index); ref = luaL_ref(lua_state(), LUA_REGISTRYINDEX); } - basic_reference(lua_State* L, lua_nil_t) noexcept - : luastate(detail::pick_main_thread(L, L)) { + basic_reference(lua_State* L, lua_nil_t) noexcept : luastate(detail::pick_main_thread(L, L)) { } ~basic_reference() noexcept { @@ -9354,12 +9405,10 @@ namespace sol { deref(); } - basic_reference(const basic_reference& o) noexcept - : stateless_reference(o.copy()), luastate(o.lua_state()) { + basic_reference(const basic_reference& o) noexcept : stateless_reference(o.copy()), luastate(o.lua_state()) { } - basic_reference(basic_reference&& o) noexcept - : stateless_reference(std::move(o)), luastate(o.lua_state()) { + basic_reference(basic_reference&& o) noexcept : stateless_reference(std::move(o)), luastate(o.lua_state()) { o.luastate = nullptr; } @@ -11165,8 +11214,10 @@ namespace sol { namespace stack { } else if constexpr (std::is_integral_v || std::is_same_v) { tracking.use(1); -#if SOL_LUA_VERSION >= 503 +#if SOL_LUA_VESION_I_ >= 503 + // Lua 5.3 and greater checks for numeric precision #if SOL_IS_ON(SOL_STRINGS_ARE_NUMBERS_I_) + // imprecise, sloppy conversions int isnum = 0; lua_tointegerx(L, index, &isnum); const bool success = isnum != 0; @@ -11174,8 +11225,8 @@ namespace sol { namespace stack { // expected type, actual type handler(L, index, type::number, type_of(L, index), detail::not_a_number_or_number_string_integral); } -#elif (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) && !(defined(SOL_NO_CHECK_NUMBER_PRECISION) && SOL_NO_CHECK_NUMBER_PRECISION) - // this check is precise, does not convert +#elif SOL_IS_ON(SOL_NUMBER_PRECISION_CHECKS_I_) + // this check is precise, do not convert if (lua_isinteger(L, index) == 1) { return true; } @@ -11185,16 +11236,18 @@ namespace sol { namespace stack { handler(L, index, type::number, type_of(L, index), detail::not_a_number_integral); } #else + // Numerics are neither safe nor string-convertible type t = type_of(L, index); const bool success = t == type::number; -#endif // If numbers are enabled, use the imprecise check +#endif if (!success) { // expected type, actual type handler(L, index, type::number, type_of(L, index), detail::not_a_number); } return success; #else -#if !defined(SOL_STRINGS_ARE_NUMBERS) || !SOL_STRINGS_ARE_NUMBERS + // Lua 5.2 and below checks +#if SOL_IS_OFF(SOL_STRINGS_ARE_NUMBERS_I_) // must pre-check, because it will convert type t = type_of(L, index); if (t != type::number) { @@ -11203,7 +11256,8 @@ namespace sol { namespace stack { return false; } #endif // Do not allow strings to be numbers -#if (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) && !(defined(SOL_NO_CHECK_NUMBER_PRECISION) && SOL_NO_CHECK_NUMBER_PRECISION) + +#if SOL_IS_ON(SOL_NUMBER_PRECISION_CHECKS_I_) int isnum = 0; const lua_Number v = lua_tonumberx(L, index, &isnum); const bool success = isnum != 0 && static_cast(llround(v)) == v; @@ -11211,17 +11265,17 @@ namespace sol { namespace stack { const bool success = true; #endif // Safe numerics and number precision checking if (!success) { - // expected type, actual type + // Use defines to provide a better error message! #if SOL_IS_ON(SOL_STRINGS_ARE_NUMBERS_I_) handler(L, index, type::number, type_of(L, index), detail::not_a_number_or_number_string); -#elif (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) +#elif SOL_IS_ON(SOL_NUMBER_PRECISION_CHECKS_I_) handler(L, index, type::number, t, detail::not_a_number_or_number_string); #else handler(L, index, type::number, t, detail::not_a_number); #endif } return success; -#endif // Lua Version 5.3 versus others +#endif } else if constexpr (std::is_floating_point_v || std::is_same_v) { tracking.use(1); @@ -11521,7 +11575,7 @@ namespace sol { namespace stack { }; template - struct unqualified_checker, type::userdata> : unqualified_checker> {}; + struct unqualified_checker, type::userdata> : unqualified_checker> { }; template struct unqualified_checker, type::userdata> { @@ -12175,7 +12229,7 @@ namespace sol { namespace stack { } else if constexpr (std::is_integral_v || std::is_same_v) { tracking.use(1); -#if SOL_LUA_VERSION >= 503 +#if SOL_LUA_VESION_I_ >= 503 if (lua_isinteger(L, index) != 0) { return static_cast(lua_tointeger(L, index)); } @@ -12374,7 +12428,7 @@ namespace sol { namespace stack { int index = lua_absindex(L, relindex); T cont; std::size_t idx = 0; -#if SOL_LUA_VERSION >= 503 +#if SOL_LUA_VESION_I_ >= 503 // This method is HIGHLY performant over regular table iteration // thanks to the Lua API changes in 5.3 // Questionable in 5.4 @@ -12385,7 +12439,7 @@ namespace sol { namespace stack { } bool isnil = false; for (int vi = 0; vi < lua_size::value; ++vi) { -#if defined(LUA_NILINTABLE) && LUA_NILINTABLE && SOL_LUA_VERSION >= 600 +#if defined(LUA_NILINTABLE) && LUA_NILINTABLE && SOL_LUA_VESION_I_ >= 600 #if SOL_IS_ON(SOL_SAFE_STACK_CHECK_I_) luaL_checkstack(L, 1, detail::not_enough_stack_space_generic); #endif // make sure stack doesn't overflow @@ -12406,7 +12460,7 @@ namespace sol { namespace stack { if (i == 0) { break; } -#if defined(LUA_NILINTABLE) && LUA_NILINTABLE && SOL_LUA_VERSION >= 600 +#if defined(LUA_NILINTABLE) && LUA_NILINTABLE && SOL_LUA_VESION_I_ >= 600 lua_pop(L, vi); #else lua_pop(L, (vi + 1)); @@ -12416,7 +12470,7 @@ namespace sol { namespace stack { } } if (isnil) { -#if defined(LUA_NILINTABLE) && LUA_NILINTABLE && SOL_LUA_VERSION >= 600 +#if defined(LUA_NILINTABLE) && LUA_NILINTABLE && SOL_LUA_VESION_I_ >= 600 #else lua_pop(L, lua_size::value); #endif @@ -12524,7 +12578,7 @@ namespace sol { namespace stack { C cont; auto at = cont.cbefore_begin(); std::size_t idx = 0; -#if SOL_LUA_VERSION >= 503 +#if SOL_LUA_VESION_I_ >= 503 // This method is HIGHLY performant over regular table iteration thanks to the Lua API changes in 5.3 for (lua_Integer i = 0;; i += lua_size::value, lua_pop(L, lua_size::value)) { if (idx >= cont.max_size()) { @@ -13123,7 +13177,7 @@ namespace sol { namespace stack { return stack_detail::unchecked_get(L, index, tracking); } else if constexpr ((std::is_integral_v || std::is_same_v)&&!std::is_same_v) { -#if SOL_LUA_VERSION >= 503 +#if SOL_LUA_VESION_I_ >= 503 if (lua_isinteger(L, index) != 0) { tracking.use(1); return static_cast(lua_tointeger(L, index)); @@ -13132,7 +13186,7 @@ namespace sol { namespace stack { int isnum = 0; const lua_Number value = lua_tonumberx(L, index, &isnum); if (isnum != 0) { -#if (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) && !(defined(SOL_NO_CHECK_NUMBER_PRECISION) && SOL_NO_CHECK_NUMBER_PRECISION) +#if SOL_IS_ON(SOL_NUMBER_PRECISION_CHECKS_I_) const auto integer_value = llround(value); if (static_cast(integer_value) == value) { tracking.use(1); @@ -13357,7 +13411,7 @@ namespace sol { namespace stack { #if SOL_IS_ON(SOL_SAFE_STACK_CHECK_I_) luaL_checkstack(L, 1, detail::not_enough_stack_space_environment); #endif // make sure stack doesn't overflow -#if SOL_LUA_VERSION < 502 +#if SOL_LUA_VESION_I_ < 502 // Use lua_getfenv lua_getfenv(L, index); #else @@ -13539,13 +13593,13 @@ namespace sol { namespace stack { #if SOL_IS_ON(SOL_SAFE_STACK_CHECK_I_) luaL_checkstack(L, 1, detail::not_enough_stack_space_integral); #endif // make sure stack doesn't overflow -#if SOL_LUA_VERSION >= 503 +#if SOL_LUA_VESION_I_ >= 503 if (stack_detail::integer_value_fits(value)) { lua_pushinteger(L, static_cast(value)); return 1; } #endif // Lua 5.3 and above -#if (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) && !(defined(SOL_NO_CHECK_NUMBER_PRECISION) && SOL_NO_CHECK_NUMBER_PRECISION) +#if SOL_IS_ON(SOL_NUMBER_PRECISION_CHECKS_I_) if (static_cast(llround(static_cast(value))) != value) { #if SOL_IS_OFF(SOL_EXCEPTIONS_I_) // Is this really worth it? @@ -13571,7 +13625,7 @@ namespace sol { namespace stack { luaL_Stream* source { std::forward(args)... }; luaL_Stream* stream = static_cast(lua_newuserdata(L, sizeof(luaL_Stream))); stream->f = source->f; -#if !defined(SOL_LUAJIT) && (SOL_LUA_VERSION > 501) +#if SOL_IS_ON(SOL_LUAL_STREAM_USE_CLOSE_FUNCTION_I_) stream->closef = source->closef; #endif // LuaJIT and Lua 5.1 and below do not have return 1; @@ -13580,7 +13634,7 @@ namespace sol { namespace stack { luaL_Stream& source(std::forward(args)...); luaL_Stream* stream = static_cast(lua_newuserdata(L, sizeof(luaL_Stream))); stream->f = source.f; -#if !defined(SOL_LUAJIT) && (SOL_LUA_VERSION > 501) +#if SOL_IS_ON(SOL_LUAL_STREAM_USE_CLOSE_FUNCTION_I_) stream->closef = source.closef; #endif // LuaJIT and Lua 5.1 and below do not have return 1; @@ -13650,7 +13704,7 @@ namespace sol { namespace stack { int tableindex = lua_gettop(L); std::size_t index = 1; for (const auto& i : cont) { -#if SOL_LUA_VERSION >= 503 +#if SOL_LUA_VESION_I_ >= 503 int p = is_nested ? stack::push(L, as_nested_ref(i)) : stack::push(L, i); for (int pi = 0; pi < p; ++pi) { lua_seti(L, tableindex, static_cast(index++)); @@ -14533,11 +14587,11 @@ namespace sol { namespace stack { template struct field_getter { static constexpr int default_table_index = meta::conditional_t < meta::is_c_str_v -#if SOL_LUA_VERSION >= 503 +#if SOL_LUA_VESION_I_ >= 503 || (std::is_integral_v && !std::is_same_v) #endif // integer global keys 5.3 or better || (raw && std::is_void_v>), - std::integral_constant, std::integral_constant> ::value; + std::integral_constant, std::integral_constant > ::value; template void get(lua_State* L, Key&& key, int tableindex = default_table_index) { @@ -14548,7 +14602,7 @@ namespace sol { namespace stack { } else if constexpr (std::is_same_v) { (void)key; -#if SOL_LUA_VERSION < 502 +#if SOL_LUA_VESION_I_ < 502 // Use lua_setfenv lua_getfenv(L, tableindex); #else @@ -14567,7 +14621,7 @@ namespace sol { namespace stack { if constexpr (std::is_integral_v && !std::is_same_v) { lua_rawgeti(L, tableindex, static_cast(key)); } -#if SOL_LUA_VERSION >= 502 +#if SOL_LUA_VESION_I_ >= 502 else if constexpr (std::is_void_v>) { lua_rawgetp(L, tableindex, key); } @@ -14587,7 +14641,7 @@ namespace sol { namespace stack { lua_getfield(L, tableindex, &key[0]); } } -#if SOL_LUA_VERSION >= 503 +#if SOL_LUA_VESION_I_ >= 503 else if constexpr (std::is_integral_v && !std::is_same_v) { lua_geti(L, tableindex, static_cast(key)); } @@ -14605,7 +14659,7 @@ namespace sol { namespace stack { template void apply(std::index_sequence<0, I...>, lua_State* L, Keys&& keys, int tableindex) { get_field(L, std::get<0>(std::forward(keys)), tableindex); - void(detail::swallow{ (get_field(L, std::get(std::forward(keys))), 0)... }); + void(detail::swallow { (get_field(L, std::get(std::forward(keys))), 0)... }); reference saved(L, -1); lua_pop(L, static_cast(sizeof...(I))); saved.push(); @@ -14648,7 +14702,7 @@ namespace sol { namespace stack { static constexpr int default_table_index = meta::conditional_t < (meta::is_c_str_v || meta::is_string_of_v) || (std::is_integral_v && !std::is_same_v) || (std::is_integral_v && !std::is_same_v) || (raw && std::is_void_v>), - std::integral_constant, std::integral_constant> ::value; + std::integral_constant, std::integral_constant > ::value; template void set(lua_State* L, Key&& key, Value&& value, int tableindex = default_table_index) { @@ -14668,7 +14722,7 @@ namespace sol { namespace stack { push(L, std::forward(value)); lua_rawseti(L, tableindex, static_cast(key)); } -#if SOL_LUA_VERSION >= 502 +#if SOL_LUA_VESION_I_ >= 502 else if constexpr (std::is_void_v>) { push(L, std::forward(value)); lua_rawsetp(L, tableindex, std::forward(key)); @@ -14692,7 +14746,7 @@ namespace sol { namespace stack { lua_setfield(L, tableindex, &key[0]); } } -#if SOL_LUA_VERSION >= 503 +#if SOL_LUA_VESION_I_ >= 503 else if constexpr (std::is_integral_v && !std::is_same_v) { push(L, std::forward(value)); lua_seti(L, tableindex, static_cast(key)); @@ -15053,7 +15107,7 @@ namespace sol { } inline void luajit_exception_handler(lua_State* L, int (*handler)(lua_State*, lua_CFunction) = detail::c_trampoline) { -#if defined(SOL_LUAJIT) && (!defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) || !(SOL_EXCEPTIONS_SAFE_PROPAGATION)) +#if SOL_IS_ON(SOL_USE_LUAJIT_EXCEPTION_TRAMPOLINE_I_) if (L == nullptr) { return; } @@ -15070,7 +15124,7 @@ namespace sol { } inline void luajit_exception_off(lua_State* L) { -#if defined(SOL_LUAJIT) +#if SOL_IS_ON(SOL_USE_LUAJIT_EXCEPTION_TRAMPOLINE_I_) if (L == nullptr) { return; } @@ -15637,12 +15691,18 @@ namespace sol { typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; - protected_function_result() = default; + protected_function_result() noexcept = default; protected_function_result(lua_State* Ls, int idx = -1, int retnum = 0, int popped = 0, call_status pferr = call_status::ok) noexcept : L(Ls), index(idx), returncount(retnum), popcount(popped), err(pferr) { } - protected_function_result(const protected_function_result&) = default; - protected_function_result& operator=(const protected_function_result&) = default; + + // We do not want anyone to copy these around willy-nilly + // Will likely break people, but also will probably get rid of quiet bugs that have + // been lurking. (E.g., Vanilla Lua will just quietly discard over-pops and under-pops: + // LuaJIT and other Lua engines will implode and segfault at random later times.) + protected_function_result(const protected_function_result&) = delete; + protected_function_result& operator=(const protected_function_result&) = delete; + protected_function_result(protected_function_result&& o) noexcept : L(o.L), index(o.index), returncount(o.returncount), popcount(o.popcount), err(o.err) { // Must be manual, otherwise destructor will screw us @@ -15829,20 +15889,24 @@ namespace sol { typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; - unsafe_function_result() = default; - unsafe_function_result(lua_State* Ls, int idx = -1, int retnum = 0) - : L(Ls), index(idx), returncount(retnum) { + unsafe_function_result() noexcept = default; + unsafe_function_result(lua_State* Ls, int idx = -1, int retnum = 0) noexcept : L(Ls), index(idx), returncount(retnum) { } - unsafe_function_result(const unsafe_function_result&) = default; - unsafe_function_result& operator=(const unsafe_function_result&) = default; - unsafe_function_result(unsafe_function_result&& o) - : L(o.L), index(o.index), returncount(o.returncount) { + + // We do not want anyone to copy these around willy-nilly + // Will likely break people, but also will probably get rid of quiet bugs that have + // been lurking. (E.g., Vanilla Lua will just quietly discard over-pops and under-pops: + // LuaJIT and other Lua engines will implode and segfault at random later times.) + unsafe_function_result(const unsafe_function_result&) = delete; + unsafe_function_result& operator=(const unsafe_function_result&) = delete; + + unsafe_function_result(unsafe_function_result&& o) noexcept : L(o.L), index(o.index), returncount(o.returncount) { // Must be manual, otherwise destructor will screw us // return count being 0 is enough to keep things clean // but will be thorough o.abandon(); } - unsafe_function_result& operator=(unsafe_function_result&& o) { + unsafe_function_result& operator=(unsafe_function_result&& o) noexcept { L = o.L; index = o.index; returncount = o.returncount; @@ -15927,7 +15991,7 @@ namespace sol { return returncount; }; void abandon() noexcept { - //L = nullptr; + // L = nullptr; index = 0; returncount = 0; } @@ -24214,19 +24278,15 @@ namespace sol { basic_environment(basic_environment&&) = default; basic_environment& operator=(const basic_environment&) = default; basic_environment& operator=(basic_environment&&) = default; - basic_environment(const stack_reference& r) - : basic_environment(r.lua_state(), r.stack_index()) { + basic_environment(const stack_reference& r) : basic_environment(r.lua_state(), r.stack_index()) { } - basic_environment(stack_reference&& r) - : basic_environment(r.lua_state(), r.stack_index()) { + basic_environment(stack_reference&& r) : basic_environment(r.lua_state(), r.stack_index()) { } - basic_environment(lua_State* L, new_table nt) - : base_t(L, std::move(nt)) { + basic_environment(lua_State* L, new_table nt) : base_t(L, std::move(nt)) { } template - basic_environment(lua_State* L, new_table t, const basic_reference& fallback) - : basic_environment(L, std::move(t)) { + basic_environment(lua_State* L, new_table t, const basic_reference& fallback) : basic_environment(L, std::move(t)) { stack_table mt(L, new_table(0, 1)); mt.set(meta_function::index, fallback); this->set(metatable_key, mt); @@ -24236,7 +24296,7 @@ namespace sol { basic_environment(env_key_t, const stack_reference& extraction_target) : base_t(detail::no_safety, extraction_target.lua_state(), (stack::push_environment_of(extraction_target), -1)) { #if SOL_IS_ON(SOL_SAFE_REFERENCES_I_) - constructor_handler handler{}; + constructor_handler handler {}; stack::check(this->lua_state(), -1, handler); #endif // Safety lua_pop(this->lua_state(), 2); @@ -24245,48 +24305,45 @@ namespace sol { basic_environment(env_key_t, const basic_reference& extraction_target) : base_t(detail::no_safety, extraction_target.lua_state(), (stack::push_environment_of(extraction_target), -1)) { #if SOL_IS_ON(SOL_SAFE_REFERENCES_I_) - constructor_handler handler{}; + constructor_handler handler {}; stack::check(this->lua_state(), -1, handler); #endif // Safety lua_pop(this->lua_state(), 2); } - basic_environment(lua_State* L, int index = -1) - : base_t(detail::no_safety, L, index) { + basic_environment(lua_State* L, int index = -1) : base_t(detail::no_safety, L, index) { #if SOL_IS_ON(SOL_SAFE_REFERENCES_I_) - constructor_handler handler{}; + constructor_handler handler {}; stack::check(L, index, handler); #endif // Safety } - basic_environment(lua_State* L, ref_index index) - : base_t(detail::no_safety, L, index) { + basic_environment(lua_State* L, ref_index index) : base_t(detail::no_safety, L, index) { #if SOL_IS_ON(SOL_SAFE_REFERENCES_I_) auto pp = stack::push_pop(*this); - constructor_handler handler{}; + constructor_handler handler {}; stack::check(L, -1, handler); #endif // Safety } - template , basic_environment>>, meta::neg>, meta::neg>>, is_lua_reference>> = meta::enabler> - basic_environment(T&& r) noexcept - : base_t(detail::no_safety, std::forward(r)) { + template , basic_environment>>, meta::neg>, + meta::neg>>, is_lua_reference>> = meta::enabler> + basic_environment(T&& r) noexcept : base_t(detail::no_safety, std::forward(r)) { #if SOL_IS_ON(SOL_SAFE_REFERENCES_I_) if (!is_environment>::value) { auto pp = stack::push_pop(*this); - constructor_handler handler{}; + constructor_handler handler {}; stack::check(lua_state(), -1, handler); } #endif // Safety } - basic_environment(lua_nil_t r) noexcept - : base_t(detail::no_safety, r) { + basic_environment(lua_nil_t r) noexcept : base_t(detail::no_safety, r) { } template >> = meta::enabler> - basic_environment(lua_State* L, T&& r) noexcept - : base_t(detail::no_safety, L, std::forward(r)) { + basic_environment(lua_State* L, T&& r) noexcept : base_t(detail::no_safety, L, std::forward(r)) { #if SOL_IS_ON(SOL_SAFE_REFERENCES_I_) if (!is_environment>::value) { auto pp = stack::push_pop(*this); - constructor_handler handler{}; + constructor_handler handler {}; stack::check(lua_state(), -1, handler); } #endif // Safety @@ -24296,7 +24353,7 @@ namespace sol { void set_on(const T& target) const { lua_State* L = target.lua_state(); auto pp = stack::push_pop(target); -#if SOL_LUA_VERSION < 502 +#if SOL_LUA_VESION_I_ < 502 // Use lua_setfenv this->push(); lua_setfenv(L, -2); @@ -24326,11 +24383,9 @@ namespace sol { struct this_environment { optional env; - this_environment() - : env(nullopt) { + this_environment() : env(nullopt) { } - this_environment(environment e) - : env(std::move(e)) { + this_environment(environment e) : env(std::move(e)) { } this_environment(const this_environment&) = default; this_environment(this_environment&&) = default; @@ -24341,11 +24396,11 @@ namespace sol { return static_cast(env); } - operator optional&() { + operator optional &() { return env; } - operator const optional&() const { + operator const optional &() const { return env; } @@ -24414,12 +24469,18 @@ namespace sol { load_status err; public: - load_result() = default; + load_result() noexcept = default; load_result(lua_State* Ls, int stackindex = -1, int retnum = 0, int popnum = 0, load_status lerr = load_status::ok) noexcept : L(Ls), index(stackindex), returncount(retnum), popcount(popnum), err(lerr) { } - load_result(const load_result&) = default; - load_result& operator=(const load_result&) = default; + + // We do not want anyone to copy these around willy-nilly + // Will likely break people, but also will probably get rid of quiet bugs that have + // been lurking. (E.g., Vanilla Lua will just quietly discard over-pops and under-pops: + // LuaJIT and other Lua engines will implode and segfault at random later times.) + load_result(const load_result&) = delete; + load_result& operator=(const load_result&) = delete; + load_result(load_result&& o) noexcept : L(o.L), index(o.index), returncount(o.returncount), popcount(o.popcount), err(o.err) { // Must be manual, otherwise destructor will screw us // return count being 0 is enough to keep things clean @@ -24666,7 +24727,7 @@ namespace sol { namespace sol { inline void register_main_thread(lua_State* L) { -#if SOL_LUA_VERSION < 502 +#if SOL_LUA_VESION_I_ < 502 if (L == nullptr) { lua_pushnil(L); lua_setglobal(L, detail::default_main_thread_name()); @@ -24749,7 +24810,7 @@ namespace sol { std::string err = "sol: "; err += to_string(result.status()); err += " error"; -#if !(defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS) +#if SOL_IS_ON(SOL_EXCEPTIONS_I_) std::exception_ptr eptr = std::current_exception(); if (eptr) { err += " with a "; @@ -24838,7 +24899,7 @@ namespace sol { bool is53mod = loaded && !(loaded->is() && !loaded->as()); if (is53mod) return loaded; -#if SOL_LUA_VERSION <= 501 +#if SOL_LUA_VESION_I_ <= 501 auto loaded51 = global.traverse_get>("package", "loaded", key); bool is51mod = loaded51 && !(loaded51->is() && !loaded51->as()); if (is51mod) @@ -24849,7 +24910,7 @@ namespace sol { template void ensure_package(const std::string& key, T&& sr) { -#if SOL_LUA_VERSION <= 501 +#if SOL_LUA_VESION_I_ <= 501 auto pkg = global["package"]; if (!pkg.valid()) { pkg = create_table_with("loaded", create_table_with(key, sr)); @@ -24912,7 +24973,7 @@ namespace sol { for (auto&& library : libraries) { switch (library) { -#if SOL_LUA_VERSION <= 501 && defined(SOL_LUAJIT) +#if SOL_LUA_VESION_I_ <= 501 && defined(SOL_LUAJIT) case lib::coroutine: #endif // luajit opens coroutine base stuff case lib::base: @@ -24925,7 +24986,7 @@ namespace sol { break; #if !defined(SOL_LUAJIT) case lib::coroutine: -#if SOL_LUA_VERSION > 501 +#if SOL_LUA_VESION_I_ > 501 luaL_requiref(L, "coroutine", luaopen_coroutine, 1); lua_pop(L, 1); #endif // Lua 5.2+ only @@ -24947,7 +25008,7 @@ namespace sol { #ifdef SOL_LUAJIT luaL_requiref(L, "bit32", luaopen_bit, 1); lua_pop(L, 1); -#elif (SOL_LUA_VERSION == 502) || defined(LUA_COMPAT_BITLIB) || defined(LUA_COMPAT_5_2) +#elif (SOL_LUA_VESION_I_ == 502) || defined(LUA_COMPAT_BITLIB) || defined(LUA_COMPAT_5_2) luaL_requiref(L, "bit32", luaopen_bit32, 1); lua_pop(L, 1); #else @@ -24966,7 +25027,7 @@ namespace sol { lua_pop(L, 1); break; case lib::utf8: -#if SOL_LUA_VERSION > 502 && !defined(SOL_LUAJIT) +#if SOL_LUA_VESION_I_ > 502 && !defined(SOL_LUAJIT) luaL_requiref(L, "utf8", luaopen_utf8, 1); lua_pop(L, 1); #endif // Lua 5.3+ only @@ -25019,7 +25080,7 @@ namespace sol { // one day Lua 5.1 will die a peaceful death // and its old bones will find blissful rest auto loaders_proxy = package -#if SOL_LUA_VERSION < 502 +#if SOL_LUA_VESION_I_ < 502 ["loaders"] #else ["searchers"] @@ -25047,7 +25108,7 @@ namespace sol { // one day Lua 5.1 will die a peaceful death // and its old bones will find blissful rest auto loaders_proxy = package -#if SOL_LUA_VERSION < 502 +#if SOL_LUA_VESION_I_ < 502 ["loaders"] #else ["searchers"] @@ -25430,7 +25491,7 @@ namespace sol { } bool supports_gc_mode(gc_mode mode) const noexcept { -#if SOL_LUA_VERSION >= 504 +#if SOL_LUA_VESION_I_ >= 504 // supports all modes (void)mode; return true; @@ -25439,7 +25500,12 @@ namespace sol { } bool is_gc_on() const { +#if SOL_LUA_VESION_I_ >= 502 return lua_gc(lua_state(), LUA_GCISRUNNING, 0) == 1; +#else + // You cannot turn it off in Lua 5.1 + return true; +#endif } void collect_garbage() { @@ -25454,7 +25520,7 @@ namespace sol { // THOUGHT: std::chrono-alikes to map "kilobyte size" here...? // Make it harder to give MB or KB to a B parameter...? // Probably overkill for now. -#if SOL_LUA_VERSION >= 504 +#if SOL_LUA_VESION_I_ >= 504 // The manual implies that this function is almost always successful... // is it?? It could depend on the GC mode... return lua_gc(lua_state(), LUA_GCSTEP, step_size_kilobytes) != 0; @@ -25479,7 +25545,7 @@ namespace sol { // THOUGHT: std::chrono-alikes to map "byte size" here...? // Make it harder to give MB or KB to a B parameter...? // Probably overkill for now. -#if SOL_LUA_VERSION >= 504 +#if SOL_LUA_VESION_I_ >= 504 int old_mode = lua_gc(lua_state(), LUA_GCINC, pause, step_multiplier, step_byte_size); if (old_mode == LUA_GCGEN) { return gc_mode::generational; @@ -25497,7 +25563,7 @@ namespace sol { // Returns the old GC mode. Check support using the supports_gc_mode function. gc_mode change_gc_mode_generational(int minor_multiplier, int major_multiplier) { -#if SOL_LUA_VERSION >= 504 +#if SOL_LUA_VESION_I_ >= 504 // "What does this shit mean?" // http://www.lua.org/manual/5.4/manual.html#2.5.2 int old_mode = lua_gc(lua_state(), LUA_GCGEN, minor_multiplier, major_multiplier); @@ -25869,7 +25935,7 @@ namespace sol { call_status stats = call_status::yielded; void luacall(std::ptrdiff_t argcount, std::ptrdiff_t) { -#if SOL_LUA_VERSION >= 504 +#if SOL_LUA_VESION_I_ >= 504 int nresults; stats = static_cast(lua_resume(lua_state(), nullptr, static_cast(argcount), &nresults)); #else @@ -25915,13 +25981,16 @@ namespace sol { using base_t::lua_state; basic_coroutine() = default; - template , basic_coroutine>>, meta::neg>>, meta::neg>, meta::neg>>, is_lua_reference>> = meta::enabler> + template , basic_coroutine>>, + meta::neg>>, meta::neg>, + meta::neg>>, is_lua_reference>> = meta::enabler> basic_coroutine(T&& r) noexcept : base_t(std::forward(r)), error_handler(detail::get_default_handler::value>(r.lua_state())) { #if SOL_IS_ON(SOL_SAFE_REFERENCES_I_) if (!is_function>::value) { auto pp = stack::push_pop(*this); - constructor_handler handler{}; + constructor_handler handler {}; stack::check(lua_state(), -1, handler); } #endif // Safety @@ -25936,11 +26005,9 @@ namespace sol { basic_coroutine(basic_function&& b) : basic_coroutine(std::move(b), detail::get_default_handler::value>(b.lua_state())) { } - basic_coroutine(const basic_function& b, handler_t eh) - : base_t(b), error_handler(std::move(eh)) { + basic_coroutine(const basic_function& b, handler_t eh) : base_t(b), error_handler(std::move(eh)) { } - basic_coroutine(basic_function&& b, handler_t eh) - : base_t(std::move(b)), error_handler(std::move(eh)) { + basic_coroutine(basic_function&& b, handler_t eh) : base_t(std::move(b)), error_handler(std::move(eh)) { } basic_coroutine(const stack_reference& r) : basic_coroutine(r.lua_state(), r.stack_index(), detail::get_default_handler::value>(r.lua_state())) { @@ -25948,11 +26015,9 @@ namespace sol { basic_coroutine(stack_reference&& r) : basic_coroutine(r.lua_state(), r.stack_index(), detail::get_default_handler::value>(r.lua_state())) { } - basic_coroutine(const stack_reference& r, handler_t eh) - : basic_coroutine(r.lua_state(), r.stack_index(), std::move(eh)) { + basic_coroutine(const stack_reference& r, handler_t eh) : basic_coroutine(r.lua_state(), r.stack_index(), std::move(eh)) { } - basic_coroutine(stack_reference&& r, handler_t eh) - : basic_coroutine(r.lua_state(), r.stack_index(), std::move(eh)) { + basic_coroutine(stack_reference&& r, handler_t eh) : basic_coroutine(r.lua_state(), r.stack_index(), std::move(eh)) { } template @@ -25963,9 +26028,9 @@ namespace sol { basic_coroutine(proxy_base&& p) : basic_coroutine(std::move(p), detail::get_default_handler::value>(p.lua_state())) { } - template >, meta::neg>>> = meta::enabler> - basic_coroutine(Proxy&& p, Handler&& eh) - : basic_coroutine(detail::force_cast(p), std::forward(eh)) { + template >, meta::neg>>> = meta::enabler> + basic_coroutine(Proxy&& p, Handler&& eh) : basic_coroutine(detail::force_cast(p), std::forward(eh)) { } template >> = meta::enabler> @@ -25973,57 +26038,51 @@ namespace sol { : basic_coroutine(L, std::forward(r), detail::get_default_handler::value>(L)) { } template >> = meta::enabler> - basic_coroutine(lua_State* L, T&& r, handler_t eh) - : base_t(L, std::forward(r)), error_handler(std::move(eh)) { + basic_coroutine(lua_State* L, T&& r, handler_t eh) : base_t(L, std::forward(r)), error_handler(std::move(eh)) { #if SOL_IS_ON(SOL_SAFE_REFERENCES_I_) auto pp = stack::push_pop(*this); - constructor_handler handler{}; + constructor_handler handler {}; stack::check(lua_state(), -1, handler); #endif // Safety } - basic_coroutine(lua_nil_t n) - : base_t(n), error_handler(n) { + basic_coroutine(lua_nil_t n) : base_t(n), error_handler(n) { } basic_coroutine(lua_State* L, int index = -1) : basic_coroutine(L, index, detail::get_default_handler::value>(L)) { } - basic_coroutine(lua_State* L, int index, handler_t eh) - : base_t(L, index), error_handler(std::move(eh)) { + basic_coroutine(lua_State* L, int index, handler_t eh) : base_t(L, index), error_handler(std::move(eh)) { #ifdef SOL_SAFE_REFERENCES - constructor_handler handler{}; + constructor_handler handler {}; stack::check(L, index, handler); #endif // Safety } basic_coroutine(lua_State* L, absolute_index index) : basic_coroutine(L, index, detail::get_default_handler::value>(L)) { } - basic_coroutine(lua_State* L, absolute_index index, handler_t eh) - : base_t(L, index), error_handler(std::move(eh)) { + basic_coroutine(lua_State* L, absolute_index index, handler_t eh) : base_t(L, index), error_handler(std::move(eh)) { #if SOL_IS_ON(SOL_SAFE_REFERENCES_I_) - constructor_handler handler{}; + constructor_handler handler {}; stack::check(L, index, handler); #endif // Safety } basic_coroutine(lua_State* L, raw_index index) : basic_coroutine(L, index, detail::get_default_handler::value>(L)) { } - basic_coroutine(lua_State* L, raw_index index, handler_t eh) - : base_t(L, index), error_handler(std::move(eh)) { + basic_coroutine(lua_State* L, raw_index index, handler_t eh) : base_t(L, index), error_handler(std::move(eh)) { #if SOL_IS_ON(SOL_SAFE_REFERENCES_I_) - constructor_handler handler{}; + constructor_handler handler {}; stack::check(L, index, handler); #endif // Safety } basic_coroutine(lua_State* L, ref_index index) : basic_coroutine(L, index, detail::get_default_handler::value>(L)) { } - basic_coroutine(lua_State* L, ref_index index, handler_t eh) - : base_t(L, index), error_handler(std::move(eh)) { + basic_coroutine(lua_State* L, ref_index index, handler_t eh) : base_t(L, index), error_handler(std::move(eh)) { #if SOL_IS_ON(SOL_SAFE_REFERENCES_I_) auto pp = stack::push_pop(*this); - constructor_handler handler{}; + constructor_handler handler {}; stack::check(lua_state(), -1, handler); #endif // Safety } @@ -26038,8 +26097,7 @@ namespace sol { } bool runnable() const noexcept { - return base_t::valid() - && (status() == call_status::yielded); + return base_t::valid() && (status() == call_status::yielded); } explicit operator bool() const noexcept { @@ -26478,13 +26536,13 @@ namespace sol { // end of sol/variadic_results.hpp -#if defined(__GNUC__) +#if SOL_IS_ON(SOL_COMPILER_GCC_I_) #pragma GCC diagnostic pop -#elif defined _MSC_VER +#elif SOL_IS_ON(SOL_COMPILER_VCXX_I_) #pragma warning(pop) #endif // g++ -#if defined(SOL_INSIDE_UNREAL) +#if SOL_IS_ON(SOL_INSIDE_UNREAL_ENGINE_I_) #undef check #pragma pop_macro("check") #endif // Unreal Engine 4 Bullshit diff --git a/tests/regression_tests/simple/source/1000 - readonly warning.cpp b/tests/regression_tests/simple/source/1000 - readonly warning.cpp new file mode 100644 index 00000000..2e35c22b --- /dev/null +++ b/tests/regression_tests/simple/source/1000 - readonly warning.cpp @@ -0,0 +1,20 @@ +#define SOL_ALL_SAFETIES_ON 1 + +#include + +struct foo1000 { + static void register_into(sol::table& table) { + table.new_usertype("foo1000", "id", sol::readonly(&foo1000::foo)); + } + int foo; +}; + +int regression_1000() { + sol::state lua; + lua.create_named_table("t"); + + sol::table t = lua["t"]; + foo1000::register_into(t); + + return 0; +} diff --git a/tests/regression_tests/simple/source/main.cpp b/tests/regression_tests/simple/source/main.cpp index 2f2027cb..fc5fed50 100644 --- a/tests/regression_tests/simple/source/main.cpp +++ b/tests/regression_tests/simple/source/main.cpp @@ -1,10 +1,11 @@ #include extern int regression_1008(); +extern int regression_1000(); int main(int, char*[]) { using f_ptr = int (*)(); - const f_ptr regressions[] = { ®ression_1008 }; + const f_ptr regressions[] = { ®ression_1008, ®ression_1000 }; const int sizeof_regressions = sizeof(regressions) / sizeof(regressions[0]); int r = 0; for (std::size_t i = 0; i < sizeof_regressions; ++i) { diff --git a/tests/runtime_tests/source/functions.cpp b/tests/runtime_tests/source/functions.cpp index d0e19ae4..ad418de3 100644 --- a/tests/runtime_tests/source/functions.cpp +++ b/tests/runtime_tests/source/functions.cpp @@ -30,13 +30,12 @@ template T va_func(sol::variadic_args va, T first) { + (void)first; T s = 0; for (auto arg : va) { T v = arg; s += v; } - std::cout << first << std::endl; - std::cout << s << std::endl; return s; } @@ -231,7 +230,7 @@ end )", REQUIRE((bool)testv); REQUIRE_FALSE((bool)testn); REQUIRE(testv.value() == 29); - sol::optional v = lua_bark(sol::optional(thing{ 29 })); + sol::optional v = lua_bark(sol::optional(thing { 29 })); REQUIRE_NOTHROW([&] { sol::lua_nil_t n = lua_bark(sol::nullopt); return n; diff --git a/tests/runtime_tests/source/operators.cpp b/tests/runtime_tests/source/operators.cpp index c33a2dcd..43cce0c6 100644 --- a/tests/runtime_tests/source/operators.cpp +++ b/tests/runtime_tests/source/operators.cpp @@ -29,7 +29,7 @@ #include #include -struct T {}; +struct T { }; TEST_CASE("operators/default", "test that generic equality operators and all sorts of equality tests can be used") { struct U { @@ -56,10 +56,10 @@ TEST_CASE("operators/default", "test that generic equality operators and all sor T& t2 = t1; T t3; U u1; - U u2{ 30 }; + U u2 { 30 }; U u3; V v1; - V v2{ 30 }; + V v2 { 30 }; V v3; lua["t1"] = &t1; lua["t2"] = &t2; @@ -74,55 +74,55 @@ TEST_CASE("operators/default", "test that generic equality operators and all sor SECTION("plain") { // Can only compare identity here { - auto result1 = lua.safe_script( - "assert(t1 == t1)" - "assert(t2 == t2)" - "assert(t3 == t3)", - sol::script_pass_on_error); - REQUIRE(result1.valid()); + sol::optional result1 = lua.safe_script( + "assert(t1 == t1)" + "assert(t2 == t2)" + "assert(t3 == t3)", + sol::script_pass_on_error); + REQUIRE_FALSE(result1.has_value()); } { auto result1 = lua.safe_script( - "assert(t1 == t2)" - "assert(not (t1 == t3))" - "assert(not (t2 == t3))", - sol::script_pass_on_error); + "assert(t1 == t2)" + "assert(not (t1 == t3))" + "assert(not (t2 == t3))", + sol::script_pass_on_error); REQUIRE(result1.valid()); } // Object should compare equal to themselves // (and not invoke operator==; pointer test should be sufficient) { auto result1 = lua.safe_script( - "assert(u1 == u1)" - "assert(u2 == u2)" - "assert(u3 == u3)", - sol::script_pass_on_error); + "assert(u1 == u1)" + "assert(u2 == u2)" + "assert(u3 == u3)", + sol::script_pass_on_error); REQUIRE(result1.valid()); } { auto result1 = lua.safe_script( - "assert(not (u1 == u2))" - "assert(u1 == u3)" - "assert(not (u2 == u3))", - sol::script_pass_on_error); + "assert(not (u1 == u2))" + "assert(u1 == u3)" + "assert(not (u2 == u3))", + sol::script_pass_on_error); REQUIRE(result1.valid()); } // Object should compare equal to themselves // (and not invoke operator==; pointer test should be sufficient) { auto result1 = lua.safe_script( - "assert(v1 == v1)" - "assert(v2 == v2)" - "assert(v3 == v3)", - sol::script_pass_on_error); + "assert(v1 == v1)" + "assert(v2 == v2)" + "assert(v3 == v3)", + sol::script_pass_on_error); REQUIRE(result1.valid()); } { auto result1 = lua.safe_script( - "assert(not (v1 == v2))" - "assert(v1 == v3)" - "assert(not (v2 == v3))", - sol::script_pass_on_error); + "assert(not (v1 == v2))" + "assert(v1 == v3)" + "assert(not (v2 == v3))", + sol::script_pass_on_error); REQUIRE(result1.valid()); } } @@ -134,54 +134,54 @@ TEST_CASE("operators/default", "test that generic equality operators and all sor // Can only compare identity here { auto result1 = lua.safe_script( - "assert(t1 == t1)" - "assert(t2 == t2)" - "assert(t3 == t3)", - sol::script_pass_on_error); + "assert(t1 == t1)" + "assert(t2 == t2)" + "assert(t3 == t3)", + sol::script_pass_on_error); REQUIRE(result1.valid()); } { auto result1 = lua.safe_script( - "assert(t1 == t2)" - "assert(not (t1 == t3))" - "assert(not (t2 == t3))", - sol::script_pass_on_error); + "assert(t1 == t2)" + "assert(not (t1 == t3))" + "assert(not (t2 == t3))", + sol::script_pass_on_error); REQUIRE(result1.valid()); } // Object should compare equal to themselves // (and not invoke operator==; pointer test should be sufficient) { auto result1 = lua.safe_script( - "assert(u1 == u1)" - "assert(u2 == u2)" - "assert(u3 == u3)", - sol::script_pass_on_error); + "assert(u1 == u1)" + "assert(u2 == u2)" + "assert(u3 == u3)", + sol::script_pass_on_error); REQUIRE(result1.valid()); } { auto result1 = lua.safe_script( - "assert(not (u1 == u2))" - "assert(u1 == u3)" - "assert(not (u2 == u3))", - sol::script_pass_on_error); + "assert(not (u1 == u2))" + "assert(u1 == u3)" + "assert(not (u2 == u3))", + sol::script_pass_on_error); REQUIRE(result1.valid()); } // Object should compare equal to themselves // (and not invoke operator==; pointer test should be sufficient) { auto result1 = lua.safe_script( - "assert(v1 == v1)" - "assert(v2 == v2)" - "assert(v3 == v3)", - sol::script_pass_on_error); + "assert(v1 == v1)" + "assert(v2 == v2)" + "assert(v3 == v3)", + sol::script_pass_on_error); REQUIRE(result1.valid()); } { auto result1 = lua.safe_script( - "assert(not (v1 == v2))" - "assert(v1 == v3)" - "assert(not (v2 == v3))", - sol::script_pass_on_error); + "assert(not (v1 == v2))" + "assert(v1 == v3)" + "assert(not (v2 == v3))", + sol::script_pass_on_error); REQUIRE(result1.valid()); } } @@ -240,9 +240,9 @@ TEST_CASE("operators/call", "test call operator generation") { lua.new_usertype("callable"); { auto result1 = lua.safe_script( - "obj = callable.new()\n" - "v = obj(2, 'bark woof')", - sol::script_pass_on_error); + "obj = callable.new()\n" + "v = obj(2, 'bark woof')", + sol::script_pass_on_error); REQUIRE(result1.valid()); int v = lua["v"]; REQUIRE(v == 11); @@ -310,7 +310,7 @@ TEST_CASE("operators/stringable", "test std::ostream stringability") { { auto result1 = lua.safe_script(R"(obj = stringable.new() print(obj) )", - sol::script_pass_on_error); + sol::script_pass_on_error); REQUIRE(result1.valid()); stringable& obj = lua["obj"]; REQUIRE(stringable::last_print_ptr == &obj);