From ffe77ccb3f22dfc52bf7abfdf80e4267f6c7c6ff Mon Sep 17 00:00:00 2001 From: ThePhD Date: Mon, 11 Feb 2019 05:50:35 -0500 Subject: [PATCH] fix some derps that aren't caught by the tests, somehow...? add more tests...! --- include/sol/call.hpp | 2 +- include/sol/stack.hpp | 2 +- single/include/sol/forward.hpp | 4 +- single/include/sol/sol.hpp | 355 ++++++++++++++++----------------- 4 files changed, 175 insertions(+), 188 deletions(-) diff --git a/include/sol/call.hpp b/include/sol/call.hpp index a550edc6..be88d2dc 100644 --- a/include/sol/call.hpp +++ b/include/sol/call.hpp @@ -581,7 +581,7 @@ namespace sol { } else { lua_call_wrapper lcw; - return lcw.call(L, std::move(rw.value()), o); + return lcw.call(L, std::move(rw.value())); } } diff --git a/include/sol/stack.hpp b/include/sol/stack.hpp index 3ab32b67..130d3d8d 100644 --- a/include/sol/stack.hpp +++ b/include/sol/stack.hpp @@ -177,7 +177,7 @@ namespace sol { call(tr, ta, L, - (std::max)(static_cast(lua_gettop(L) - expected_count::value), static_cast(0)), + (std::max)(static_cast(lua_gettop(L) - expected_count_t::value), static_cast(0)), std::forward(fx), std::forward(args)...); } diff --git a/single/include/sol/forward.hpp b/single/include/sol/forward.hpp index 17d7122a..e3bd1163 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 2019-02-10 18:04:01.576518 UTC -// This header was generated with sol v2.20.6 (revision fbf5b48) +// Generated 2019-02-11 10:50:20.059748 UTC +// This header was generated with sol v2.20.6 (revision 4fd197d) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP diff --git a/single/include/sol/sol.hpp b/single/include/sol/sol.hpp index ad47d205..a5b50df1 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 2019-02-10 18:04:01.131525 UTC -// This header was generated with sol v2.20.6 (revision fbf5b48) +// Generated 2019-02-11 10:50:18.478770 UTC +// This header was generated with sol v2.20.6 (revision 4fd197d) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -5823,6 +5823,75 @@ namespace sol { // end of sol/filters.hpp +// beginning of sol/ebco.hpp + +namespace sol { namespace detail { + + template + struct ebco { + T value_; + + ebco() = default; + ebco(const ebco&) = default; + ebco(ebco&&) = default; + ebco& operator=(const ebco&) = default; + ebco& operator=(ebco&&) = default; + ebco(const T& v) : value_(v){}; + ebco(T&& v) : value_(std::move(v)){}; + ebco& operator=(const T& v) { + value = v; + } + ebco& operator=(T&& v) { + value_ = std::move(v); + }; + template >, + ebco> && !std::is_same_v>, T>>> + ebco(Arg&& arg, Args&&... args) : T(std::forward(arg), std::forward(args)...){}; + + T& value() { + return value_; + } + + T const& value() const { + return value_; + } + }; + + template + struct ebco && std::is_class_v && !std::is_final_v>> : T { + ebco() = default; + ebco(const ebco&) = default; + ebco(ebco&&) = default; + ebco(const T& v) : T(v){}; + ebco(T&& v) : T(std::move(v)){}; + template >, + ebco> && !std::is_same_v>, T>>> + ebco(Arg&& arg, Args&&... args) : T(std::forward(arg), std::forward(args)...){}; + + ebco& operator=(const ebco&) = default; + ebco& operator=(ebco&&) = default; + ebco& operator=(const T& v) { + static_cast(*this) = v; + } + ebco& operator=(T&& v) { + static_cast(*this) = std::move(v); + }; + + T& value() { + return static_cast(*this); + } + + T const& value() const { + return static_cast(*this); + } + }; + +}} // namespace sol::detail + +// end of sol/ebco.hpp + #include #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES #ifdef SOL_STD_VARIANT @@ -6281,10 +6350,11 @@ namespace sol { } template - struct force_t { - T arg; - - force_t(T value) : arg(value) {} + struct force_t : detail::ebco { + private: + using base_t = detail::ebco; + public: + using base_t::base_t; }; template @@ -6868,7 +6938,7 @@ namespace sol { struct lua_type_of : std::integral_constant {}; #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES -#ifdef SOL_STD_VARIANT +#if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT template struct lua_type_of> : std::integral_constant {}; #endif // SOL_STD_VARIANT @@ -11307,6 +11377,7 @@ namespace sol { namespace stack { #endif continue; } + push_back_at_end(meta::has_push_back(), t, L, arr, idx); ++idx; lua_pop(L, lua_size::value); @@ -13947,7 +14018,7 @@ namespace sol { call(tr, ta, L, - (std::max)(static_cast(lua_gettop(L) - expected_count::value), static_cast(0)), + (std::max)(static_cast(lua_gettop(L) - expected_count_t::value), static_cast(0)), std::forward(fx), std::forward(args)...); } @@ -15246,101 +15317,37 @@ namespace function_detail { // beginning of sol/property.hpp -// beginning of sol/ebco.hpp - -namespace sol { - - template - struct ebco { - T value; - - ebco() = default; - ebco(const ebco&) = default; - ebco(ebco&&) = default; - ebco& operator=(const ebco&) = default; - ebco& operator=(ebco&&) = default; - ebco(const T& v) : value(v){}; - ebco(T&& v) : value(std::move(v)){}; - ebco& operator=(const T& v) { - value = v; - } - ebco& operator=(T&& v) { - value = std::move(v); - }; - template >, - ebco> && !std::is_same_v>, T>>> - ebco(Arg&& arg, Args&&... args) : T(std::forward(arg), std::forward(args)...){}; - - T& get_value() { - return value; - } - - T const& get_value() const { - return value; - } - }; - - template - struct ebco && !std::is_final_v>> : T { - ebco() = default; - ebco(const ebco&) = default; - ebco(ebco&&) = default; - ebco(const T& v) : T(v){}; - ebco(T&& v) : T(std::move(v)){}; - template >, - ebco> && !std::is_same_v>, T>>> - ebco(Arg&& arg, Args&&... args) : T(std::forward(arg), std::forward(args)...){}; - - ebco& operator=(const ebco&) = default; - ebco& operator=(ebco&&) = default; - ebco& operator=(const T& v) { - static_cast(*this) = v; - } - ebco& operator=(T&& v) { - static_cast(*this) = std::move(v); - }; - - T& get_value() { - return static_cast(*this); - } - - T const& get_value() const { - return static_cast(*this); - } - }; - -} // namespace sol - -// end of sol/ebco.hpp - namespace sol { namespace detail { struct no_prop {}; } template - struct property_wrapper : ebco, ebco { + struct property_wrapper : detail::ebco, detail::ebco { + private: + using read_base_t = detail::ebco; + using write_base_t = detail::ebco; + + public: template property_wrapper(Rx&& r, Wx&& w) - : ebco(std::forward(r)), ebco(std::forward(w)) { + : read_base_t(std::forward(r)), write_base_t(std::forward(w)) { } W& write() { - return ebco::get_value(); + return write_base_t::value(); } const W& write() const { - return ebco::get_value(); + return write_base_t::value(); } R& read() { - return ebco::get_value(); + return read_base_t::value(); } const R& read() const { - return ebco::get_value(); + return read_base_t::value(); } }; @@ -15378,17 +15385,18 @@ namespace sol { } template - struct readonly_wrapper : ebco { + struct readonly_wrapper : detail::ebco { private: - using base_t = ebco; + using base_t = detail::ebco; + public: using base_t::base_t; operator T&() { - return base_t::get_value(); + return base_t::value(); } operator const T&() const { - return base_t::get_value(); + return base_t::value(); } }; @@ -15399,9 +15407,10 @@ namespace sol { } template - struct var_wrapper : ebco { + struct var_wrapper : detail::ebco { private: - using base_t = ebco; + using base_t = detail::ebco; + public: using base_t::base_t; }; @@ -15792,11 +15801,11 @@ namespace sol { template static int call(lua_State* L, F&& f) { if constexpr (is_index) { - constexpr bool is_stack = is_stack_based_v>; + constexpr bool is_stack = is_stack_based_v>; if constexpr (clean_stack && !is_stack) { lua_settop(L, 0); } - return stack::push_reference(L, detail::unwrap(f.get_value())); + return stack::push_reference(L, detail::unwrap(f.value())); } else { if constexpr (std::is_const_v>) { @@ -15805,7 +15814,7 @@ namespace sol { else { using R = meta::unwrapped_t; if constexpr (std::is_assignable_v>, R>) { - detail::unwrap(f.get_value()) = stack::unqualified_get>(L, boost + (is_variable ? 3 : 1)); + detail::unwrap(f.value()) = stack::unqualified_get>(L, boost + (is_variable ? 3 : 1)); if (clean_stack) { lua_settop(L, 0); } @@ -15906,54 +15915,81 @@ namespace sol { } } else if constexpr (std::is_member_object_pointer_v) { - using traits_type = lua_bind_traits; using wrap = wrapper; using object_type = typename wrap::object_type; - using return_type = typename traits_type::return_type; - constexpr bool is_const = std::is_const_v>; - if constexpr (is_const) { - (void)fx; - (void)detail::swallow{ 0, (static_cast(args), 0)... }; - return luaL_error(L, "sol: cannot write to a readonly (const) variable"); - } - else { - using u_return_type = meta::unqualified_t; - constexpr bool is_assignable = std::is_copy_assignable_v || std::is_array_v; - if constexpr (!is_assignable) { - (void)fx; - (void)detail::swallow{ 0, ((void)args, 0)... }; - return luaL_error(L, "sol: cannot write to this variable: copy assignment/constructor not available"); + if constexpr (is_index) { + if constexpr (sizeof...(Args) < 1) { + using Ta = std::conditional_t, object_type, T>; +#if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE + auto maybeo = stack::check_get(L, 1); + if (!maybeo || maybeo.value() == nullptr) { + if (is_variable) { + return luaL_error(L, "sol: 'self' argument is lua_nil (bad '.' access?)"); + } + return luaL_error(L, "sol: 'self' argument is lua_nil (pass 'self' as first argument)"); + } + object_type* o = static_cast(maybeo.value()); + return call(L, std::forward(fx), *o); +#else + object_type& o = static_cast(*stack::get>(L, 1)); + return call(L, std::forward(fx), o); +#endif // Safety } else { - using args_list = typename wrap::args_list; + using returns_list = typename wrap::returns_list; using caller = typename wrap::caller; - if constexpr (sizeof...(Args) > 0) { - return stack::call_into_lua(types(), - args_list(), - L, - boost + (is_variable ? 3 : 2), - caller(), - std::forward(fx), - std::forward(args)...); + return stack::call_into_lua( + returns_list(), types<>(), L, boost + (is_variable ? 3 : 2), caller(), std::forward(fx), std::forward(args)...); + } + } + else { + using traits_type = lua_bind_traits; + using return_type = typename traits_type::return_type; + constexpr bool is_const = std::is_const_v>; + if constexpr (is_const) { + (void)fx; + (void)detail::swallow{ 0, (static_cast(args), 0)... }; + return luaL_error(L, "sol: cannot write to a readonly (const) variable"); + } + else { + using u_return_type = meta::unqualified_t; + constexpr bool is_assignable = std::is_copy_assignable_v || std::is_array_v; + if constexpr (!is_assignable) { + (void)fx; + (void)detail::swallow{ 0, ((void)args, 0)... }; + return luaL_error(L, "sol: cannot write to this variable: copy assignment/constructor not available"); } else { - using Ta = std::conditional_t, object_type, T>; -#if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE - auto maybeo = stack::check_get(L, 1); - if (!maybeo || maybeo.value() == nullptr) { - if (is_variable) { - return luaL_error(L, "sol: received nil for 'self' argument (bad '.' access?)"); - } - return luaL_error(L, "sol: received nil for 'self' argument (pass 'self' as first argument)"); + using args_list = typename wrap::args_list; + using caller = typename wrap::caller; + if constexpr (sizeof...(Args) > 0) { + return stack::call_into_lua(types(), + args_list(), + L, + boost + (is_variable ? 3 : 2), + caller(), + std::forward(fx), + std::forward(args)...); } - object_type* po = static_cast(maybeo.value()); - object_type& o = *po; -#else - object_type& o = static_cast(*stack::get>(L, 1)); -#endif // Safety + else { + using Ta = std::conditional_t, object_type, T>; + #if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE + auto maybeo = stack::check_get(L, 1); + if (!maybeo || maybeo.value() == nullptr) { + if (is_variable) { + return luaL_error(L, "sol: received nil for 'self' argument (bad '.' access?)"); + } + return luaL_error(L, "sol: received nil for 'self' argument (pass 'self' as first argument)"); + } + object_type* po = static_cast(maybeo.value()); + object_type& o = *po; + #else + object_type& o = static_cast(*stack::get>(L, 1)); + #endif // Safety - return stack::call_into_lua( - types(), args_list(), L, boost + (is_variable ? 3 : 2), caller(), std::forward(fx), o); + return stack::call_into_lua( + types(), args_list(), L, boost + (is_variable ? 3 : 2), caller(), std::forward(fx), o); + } } } } @@ -15965,55 +16001,6 @@ namespace sol { } }; - template - struct lua_call_wrapper::value>> { - using traits_type = lua_bind_traits; - using wrap = wrapper; - using object_type = typename wrap::object_type; - - template - static int call(lua_State* L, V&& v, object_type& o) { - using returns_list = typename wrap::returns_list; - using caller = typename wrap::caller; - F f(std::forward(v)); - return stack::call_into_lua(returns_list(), types<>(), L, boost + (is_variable ? 3 : 2), caller(), f, o); - } - - template - static int call(lua_State* L, V&& f) { - using Ta = std::conditional_t::value, object_type, T>; -#if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE - auto maybeo = stack::check_get(L, 1); - if (!maybeo || maybeo.value() == nullptr) { - if (is_variable) { - return luaL_error(L, "sol: 'self' argument is lua_nil (bad '.' access?)"); - } - return luaL_error(L, "sol: 'self' argument is lua_nil (pass 'self' as first argument)"); - } - object_type* o = static_cast(maybeo.value()); - return call(L, f, *o); -#else - object_type& o = static_cast(*stack::get>(L, 1)); - return call(L, f, o); -#endif // Safety - } - }; - - template - struct lua_call_wrapper, false, is_variable, checked, boost, clean_stack, C> { - using traits_type = lua_bind_traits; - using wrap = wrapper; - using object_type = typename wrap::object_type; - - static int call(lua_State* L, const readonly_wrapper&) { - return luaL_error(L, "sol: cannot write to a sol::readonly variable"); - } - - static int call(lua_State* L, const readonly_wrapper& rw, object_type&) { - return call(L, rw); - } - }; - template struct lua_call_wrapper, is_index, is_variable, checked, boost, clean_stack, C> { using traits_type = lua_bind_traits; @@ -16027,7 +16014,7 @@ namespace sol { } else { lua_call_wrapper lcw; - return lcw.call(L, std::move(rw.get_value()), o); + return lcw.call(L, std::move(rw.value())); } } @@ -16038,7 +16025,7 @@ namespace sol { } else { lua_call_wrapper lcw; - return lcw.call(L, rw.get_value(), o); + return lcw.call(L, rw.value(), o); } } @@ -16049,7 +16036,7 @@ namespace sol { } else { lua_call_wrapper lcw; - return lcw.call(L, rw.get_value()); + return lcw.call(L, rw.value()); } } @@ -16060,7 +16047,7 @@ namespace sol { } else { lua_call_wrapper lcw; - return lcw.call(L, rw.get_value(), o); + return lcw.call(L, rw.value(), o); } } };