From 4906e43918414f7d310990cf579c7538c43a9183 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 21 Nov 2018 15:03:45 -0500 Subject: [PATCH] beep boop fixes --- single/sol/sol.hpp | 34 ++++++++++++++++++++++++++++----- single/sol/sol_forward.hpp | 4 ++-- sol/stack_check_unqualified.hpp | 26 +++++++++++++++++++++++-- sol/types.hpp | 4 ++++ tests/test_utility.cpp | 20 ++++++++++++++++++- 5 files changed, 78 insertions(+), 10 deletions(-) diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index 91307e0d..4face5d8 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 2018-11-21 12:34:11.276133 UTC -// This header was generated with sol v2.20.5 (revision 157db07) +// Generated 2018-11-21 20:02:05.860519 UTC +// This header was generated with sol v2.20.5 (revision 55e9205) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -4618,6 +4618,7 @@ namespace sol { // end of sol/filters.hpp #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES +#include #ifdef SOL_STD_VARIANT #include #endif @@ -5574,6 +5575,9 @@ namespace sol { template struct lua_type_of> : std::integral_constant {}; + template + struct lua_type_of> : std::integral_constant {}; + template <> struct lua_type_of : std::integral_constant {}; @@ -7148,7 +7152,6 @@ namespace sol { #include #include #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES -#include #endif // C++17 namespace sol { @@ -8157,8 +8160,8 @@ namespace sol { // beginning of sol/stack_check_unqualified.hpp #include -#ifdef SOL_CXX17_FEATURES -#ifdef SOL_STD_VARIANT +#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES +#if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT #endif // SOL_STD_VARIANT #endif // SOL_CXX17_FEATURES @@ -8734,7 +8737,26 @@ namespace stack { }; #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES + + template + struct checker, type::poly, C> { + template + static bool check(lua_State* L, int index, Handler&&, record& tracking) { + type t = type_of(L, index); + if (t == type::none) { + tracking.use(0); + return true; + } + if (t == type::lua_nil) { + tracking.use(1); + return true; + } + return stack::check(L, index, no_panic, tracking); + } + }; + #if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT + template struct checker, type::poly, C> { typedef std::variant V; @@ -8765,7 +8787,9 @@ namespace stack { return is_one(std::integral_constant(), L, index, std::forward(handler), tracking); } }; + #endif // SOL_STD_VARIANT + #endif // SOL_CXX17_FEATURES } } // namespace sol::stack diff --git a/single/sol/sol_forward.hpp b/single/sol/sol_forward.hpp index 7d252a6d..8aa0428f 100644 --- a/single/sol/sol_forward.hpp +++ b/single/sol/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 2018-11-21 12:34:11.544452 UTC -// This header was generated with sol v2.20.5 (revision 157db07) +// Generated 2018-11-21 20:02:06.079930 UTC +// This header was generated with sol v2.20.5 (revision 55e9205) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP diff --git a/sol/stack_check_unqualified.hpp b/sol/stack_check_unqualified.hpp index e63a70e2..52d68f28 100644 --- a/sol/stack_check_unqualified.hpp +++ b/sol/stack_check_unqualified.hpp @@ -31,8 +31,9 @@ #include #include #include -#ifdef SOL_CXX17_FEATURES -#ifdef SOL_STD_VARIANT +#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES +#include +#if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT #include #endif // SOL_STD_VARIANT #endif // SOL_CXX17_FEATURES @@ -609,7 +610,26 @@ namespace stack { }; #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES + + template + struct checker, type::poly, C> { + template + static bool check(lua_State* L, int index, Handler&&, record& tracking) { + type t = type_of(L, index); + if (t == type::none) { + tracking.use(0); + return true; + } + if (t == type::lua_nil) { + tracking.use(1); + return true; + } + return stack::check(L, index, no_panic, tracking); + } + }; + #if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT + template struct checker, type::poly, C> { typedef std::variant V; @@ -640,7 +660,9 @@ namespace stack { return is_one(std::integral_constant(), L, index, std::forward(handler), tracking); } }; + #endif // SOL_STD_VARIANT + #endif // SOL_CXX17_FEATURES } } // namespace sol::stack diff --git a/sol/types.hpp b/sol/types.hpp index 90efe329..33257cf4 100644 --- a/sol/types.hpp +++ b/sol/types.hpp @@ -39,6 +39,7 @@ #include #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES #include +#include #ifdef SOL_STD_VARIANT #include #endif @@ -995,6 +996,9 @@ namespace sol { template struct lua_type_of> : std::integral_constant {}; + template + struct lua_type_of> : std::integral_constant {}; + template <> struct lua_type_of : std::integral_constant {}; diff --git a/tests/test_utility.cpp b/tests/test_utility.cpp index 062c7ac8..5dd81ac3 100644 --- a/tests/test_utility.cpp +++ b/tests/test_utility.cpp @@ -36,7 +36,6 @@ std::mutex basic_init_require_mutex; void basic_initialization_and_lib_open() { - sol::state lua; try { lua.open_libraries(); @@ -149,6 +148,25 @@ TEST_CASE("utility/optional", "test that shit optional can be round-tripped") { REQUIRE_FALSE(result.valid()); }; } + SECTION("in classes") { + sol::state lua; + lua.open_libraries(sol::lib::base); + + struct opt_c { + std::optional member; + }; + + auto uto = lua.new_usertype("opt_c", + "value", &opt_c::member); + + opt_c obj; + lua["obj"] = std::ref(obj); + + lua.safe_script("print(obj.value) obj.value = 20 print(obj.value)"); + REQUIRE(obj.member == 20); + lua.safe_script("print(obj.value) obj.value = nil print(obj.value)"); + REQUIRE(obj.member == std::nullopt); + } #else REQUIRE(true); #endif // C++17