From 0114882e135857b82ae81248f42171349bf2040c Mon Sep 17 00:00:00 2001 From: ThePhD Date: Fri, 22 Sep 2017 07:30:41 -0400 Subject: [PATCH] force usage of `lua_nil` across everything and add a proper macro / feature-test for it --- single/sol/sol.hpp | 34 ++++++++++++++++++------------ sol/feature_test.hpp | 12 ++++++++--- sol/stack_get.hpp | 12 +++++------ sol/types.hpp | 6 +++--- tests/test_container_semantics.cpp | 4 ++-- tests/test_functions.cpp | 10 ++++----- tests/tests.cpp | 8 +++---- 7 files changed, 49 insertions(+), 37 deletions(-) diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index 92ea4cf6..cd2d9c6e 100644 --- a/single/sol/sol.hpp +++ b/single/sol/sol.hpp @@ -20,8 +20,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. -// Generated 2017-09-22 01:32:30.111717 UTC -// This header was generated with sol v2.18.2 (revision 61d610b) +// Generated 2017-09-22 11:30:13.483049 UTC +// This header was generated with sol v2.18.3 (revision 1b23ad8) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -95,7 +95,7 @@ #ifndef SOL_CHECK_ARGUMENTS #endif // Check Arguments #ifndef SOL_SAFE_USERTYPE -#define SOL_SAFE_USERTYPE +#define SOL_SAFE_USERTYPE 1 #endif // Safe Usertypes #endif // NDEBUG #endif // Debug @@ -118,7 +118,7 @@ #ifndef SOL_CHECK_ARGUMENTS #endif // Check Arguments #ifndef SOL_SAFE_USERTYPE -#define SOL_SAFE_USERTYPE +#define SOL_SAFE_USERTYPE 1 #endif // Safe Usertypes #endif // g++ optimizer flag #endif // Not Debug @@ -139,10 +139,16 @@ #ifndef SOL_SAFE_USERTYPE #ifdef SOL_CHECK_ARGUMENTS -#define SOL_SAFE_USERTYPE +#define SOL_SAFE_USERTYPE 1 #endif // Turn on Safety for all #endif // Safe Usertypes +#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || defined(__OBJC__) || defined(nil) +#ifndef SOL_NO_NIL +#define SOL_NO_NIL 1 +#endif +#endif // avoiding nil defines / keywords + // end of sol/feature_test.hpp namespace sol { @@ -4516,7 +4522,7 @@ namespace sol { inline bool operator!=(lua_nil_t, lua_nil_t) { return false; } -#ifndef __OBJC__ +#if !defined(SOL_NO_NIL) typedef lua_nil_t nil_t; const nil_t nil{}; #endif @@ -4921,7 +4927,7 @@ namespace sol { enum class type : int { none = LUA_TNONE, lua_nil = LUA_TNIL, -#if !defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || !defined(__OBJC__) || !defined(nil) +#if !defined(SOL_NO_NIL) nil = lua_nil, #endif // Objective C/C++ Keyword that's found in OSX SDK and OBJC -- check for all forms to protect string = LUA_TSTRING, @@ -5389,7 +5395,7 @@ namespace sol { template struct is_main_threaded : std::is_base_of {}; - + template struct is_stack_based : std::is_base_of {}; @@ -7682,8 +7688,8 @@ namespace stack { } bool isnil = false; for (int vi = 0; vi < lua_size::value; ++vi) { - type t = static_cast(lua_geti(L, index, i + vi)); - isnil = t == type::lua_nil; + type vt = static_cast(lua_geti(L, index, i + vi)); + isnil = vt == type::lua_nil; if (isnil) { if (i == 0) { break; @@ -8128,7 +8134,7 @@ namespace stack { struct getter { static this_state get(lua_State* L, int, record& tracking) { tracking.use(0); - return this_state( L ); + return this_state(L); } }; @@ -8136,7 +8142,7 @@ namespace stack { struct getter { static this_main_state get(lua_State* L, int, record& tracking) { tracking.use(0); - return this_main_state( main_thread(L, L) ); + return this_main_state(main_thread(L, L)); } }; @@ -8279,7 +8285,7 @@ namespace stack { template static R apply(std::index_sequence<>, lua_State*, int, record&, Args&&... args) { // Fuck you too, VC++ - return R{std::forward(args)...}; + return R{ std::forward(args)... }; } template @@ -8297,7 +8303,7 @@ namespace stack { template struct getter> { static decltype(auto) get(lua_State* L, int index, record& tracking) { - return std::pair(L, index)), decltype(stack::get(L, index))>{stack::get(L, index, tracking), stack::get(L, index + tracking.used, tracking)}; + return std::pair(L, index)), decltype(stack::get(L, index))>{ stack::get(L, index, tracking), stack::get(L, index + tracking.used, tracking) }; } }; diff --git a/sol/feature_test.hpp b/sol/feature_test.hpp index b3f85358..b80debeb 100644 --- a/sol/feature_test.hpp +++ b/sol/feature_test.hpp @@ -57,7 +57,7 @@ //#define SOL_CHECK_ARGUMENTS #endif // Check Arguments #ifndef SOL_SAFE_USERTYPE -#define SOL_SAFE_USERTYPE +#define SOL_SAFE_USERTYPE 1 #endif // Safe Usertypes #endif // NDEBUG #endif // Debug @@ -83,7 +83,7 @@ // But do check userdata by default: #endif // Check Arguments #ifndef SOL_SAFE_USERTYPE -#define SOL_SAFE_USERTYPE +#define SOL_SAFE_USERTYPE 1 #endif // Safe Usertypes #endif // g++ optimizer flag #endif // Not Debug @@ -104,8 +104,14 @@ #ifndef SOL_SAFE_USERTYPE #ifdef SOL_CHECK_ARGUMENTS -#define SOL_SAFE_USERTYPE +#define SOL_SAFE_USERTYPE 1 #endif // Turn on Safety for all #endif // Safe Usertypes +#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || defined(__OBJC__) || defined(nil) +#ifndef SOL_NO_NIL +#define SOL_NO_NIL 1 +#endif +#endif // avoiding nil defines / keywords + #endif // SOL_FEATURE_TEST_HPP diff --git a/sol/stack_get.hpp b/sol/stack_get.hpp index a5a77bb6..de191c56 100644 --- a/sol/stack_get.hpp +++ b/sol/stack_get.hpp @@ -129,8 +129,8 @@ namespace stack { } bool isnil = false; for (int vi = 0; vi < lua_size::value; ++vi) { - type t = static_cast(lua_geti(L, index, i + vi)); - isnil = t == type::lua_nil; + type vt = static_cast(lua_geti(L, index, i + vi)); + isnil = vt == type::lua_nil; if (isnil) { if (i == 0) { break; @@ -575,7 +575,7 @@ namespace stack { struct getter { static this_state get(lua_State* L, int, record& tracking) { tracking.use(0); - return this_state( L ); + return this_state(L); } }; @@ -583,7 +583,7 @@ namespace stack { struct getter { static this_main_state get(lua_State* L, int, record& tracking) { tracking.use(0); - return this_main_state( main_thread(L, L) ); + return this_main_state(main_thread(L, L)); } }; @@ -726,7 +726,7 @@ namespace stack { template static R apply(std::index_sequence<>, lua_State*, int, record&, Args&&... args) { // Fuck you too, VC++ - return R{std::forward(args)...}; + return R{ std::forward(args)... }; } template @@ -744,7 +744,7 @@ namespace stack { template struct getter> { static decltype(auto) get(lua_State* L, int index, record& tracking) { - return std::pair(L, index)), decltype(stack::get(L, index))>{stack::get(L, index, tracking), stack::get(L, index + tracking.used, tracking)}; + return std::pair(L, index)), decltype(stack::get(L, index))>{ stack::get(L, index, tracking), stack::get(L, index + tracking.used, tracking) }; } }; diff --git a/sol/types.hpp b/sol/types.hpp index 747298fd..c407ccc4 100644 --- a/sol/types.hpp +++ b/sol/types.hpp @@ -182,7 +182,7 @@ namespace sol { inline bool operator!=(lua_nil_t, lua_nil_t) { return false; } -#ifndef __OBJC__ +#if !defined(SOL_NO_NIL) typedef lua_nil_t nil_t; const nil_t nil{}; #endif @@ -587,7 +587,7 @@ namespace sol { enum class type : int { none = LUA_TNONE, lua_nil = LUA_TNIL, -#if !defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || !defined(__OBJC__) || !defined(nil) +#if !defined(SOL_NO_NIL) nil = lua_nil, #endif // Objective C/C++ Keyword that's found in OSX SDK and OBJC -- check for all forms to protect string = LUA_TSTRING, @@ -1055,7 +1055,7 @@ namespace sol { template struct is_main_threaded : std::is_base_of {}; - + template struct is_stack_based : std::is_base_of {}; diff --git a/tests/test_container_semantics.cpp b/tests/test_container_semantics.cpp index 8ded28f6..4ee3c32f 100644 --- a/tests/test_container_semantics.cpp +++ b/tests/test_container_semantics.cpp @@ -967,14 +967,14 @@ end int r = sf(set, 8); REQUIRE(r == 8); sol::object rn = sf(set, 9); - REQUIRE(rn == sol::nil); + REQUIRE(rn == sol::lua_nil); } { int r = sf(map, 3); REQUIRE(r == 6); sol::object rn = sf(map, 9); - REQUIRE(rn == sol::nil); + REQUIRE(rn == sol::lua_nil); } i(lua["arr"]); diff --git a/tests/test_functions.cpp b/tests/test_functions.cpp index 1bb42abd..d080cc9c 100644 --- a/tests/test_functions.cpp +++ b/tests/test_functions.cpp @@ -664,8 +664,8 @@ TEST_CASE("advanced/get and call", "Checks for lambdas returning values after a REQUIRE_NOTHROW(lua.set_function("h", [] {})); REQUIRE_NOTHROW(lua.get("h").call()); - REQUIRE_NOTHROW(lua.set_function("i", [] { return sol::nil; })); - REQUIRE(lua.get("i").call() == sol::nil); + REQUIRE_NOTHROW(lua.set_function("i", [] { return sol::lua_nil; })); + REQUIRE(lua.get("i").call() == sol::lua_nil); REQUIRE_NOTHROW(lua.set_function("j", [] { return std::make_tuple(1, 6.28f, 3.14, std::string("heh")); })); REQUIRE((lua.get("j").call() == heh_tuple)); } @@ -699,8 +699,8 @@ TEST_CASE("advanced/operator[] call", "Checks for lambdas returning values using REQUIRE_NOTHROW(lua.set_function("h", [] {})); REQUIRE_NOTHROW(lua["h"].call()); - REQUIRE_NOTHROW(lua.set_function("i", [] { return sol::nil; })); - REQUIRE(lua["i"].call() == sol::nil); + REQUIRE_NOTHROW(lua.set_function("i", [] { return sol::lua_nil; })); + REQUIRE(lua["i"].call() == sol::lua_nil); REQUIRE_NOTHROW(lua.set_function("j", [] { return std::make_tuple(1, 6.28f, 3.14, std::string("heh")); })); REQUIRE((lua["j"].call() == heh_tuple)); } @@ -848,7 +848,7 @@ TEST_CASE("functions/stack atomic", "make sure functions don't impede on the sta REQUIRE(sg.check_stack()); { - sol::protected_function_result errresult = Stringtest(sol::nil); + sol::protected_function_result errresult = Stringtest(sol::lua_nil); REQUIRE_FALSE(errresult.valid()); sol::error err = errresult; std::string msg = err.what(); diff --git a/tests/tests.cpp b/tests/tests.cpp index d50b206d..c7cf1169 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -275,7 +275,7 @@ TEST_CASE("object/conversions", "make sure all basic reference types can be made auto osl = sol::make_object(lua, "Bark bark bark"); auto os = sol::make_object(lua, somestring); - auto omn = sol::make_object(lua, sol::nil); + auto omn = sol::make_object(lua, sol::lua_nil); REQUIRE(ot.get_type() == sol::type::table); REQUIRE(ot2.get_type() == sol::type::table); @@ -329,7 +329,7 @@ TEST_CASE("object/main_* conversions", "make sure all basic reference types can auto osl = sol::make_object(lua, "Bark bark bark"); auto os = sol::make_object(lua, somestring); - auto omn = sol::make_object(lua, sol::nil); + auto omn = sol::make_object(lua, sol::lua_nil); REQUIRE(ot.get_type() == sol::type::table); REQUIRE(ot2.get_type() == sol::type::table); @@ -554,14 +554,14 @@ TEST_CASE("proxy/proper-pushing", "allow proxies to reference other proxies and TEST_CASE("proxy/equality", "check to make sure equality tests work") { sol::state lua; - REQUIRE((lua["a"] == sol::nil)); + REQUIRE((lua["a"] == sol::lua_nil)); REQUIRE_FALSE((lua["a"] == nullptr)); REQUIRE_FALSE((lua["a"] == 0)); REQUIRE_FALSE((lua["a"] == 2)); lua["a"] = 2; - REQUIRE_FALSE((lua["a"] == sol::nil)); //0 + REQUIRE_FALSE((lua["a"] == sol::lua_nil)); //0 REQUIRE_FALSE((lua["a"] == nullptr)); //0 REQUIRE_FALSE((lua["a"] == 0)); //0 REQUIRE((lua["a"] == 2)); //1