diff --git a/include/sol/call.hpp b/include/sol/call.hpp index be88d2dc..9a94e99a 100644 --- a/include/sol/call.hpp +++ b/include/sol/call.hpp @@ -170,8 +170,7 @@ namespace sol { } } stack::record tracking{}; - stack::stack_detail::check_types ct{}; - if (!ct.check(args_list(), L, start, no_panic, tracking)) { + if (!stack::stack_detail::check_types(args_list(), L, start, no_panic, tracking)) { return overload_match_arity(types(), std::index_sequence(), std::index_sequence(), @@ -261,16 +260,15 @@ namespace sol { } } stack::record tracking{}; - stack::stack_detail::check_types ct{}; - if (!ct.check(args_list(), L, start, no_panic, tracking)) { - return overload_match_arity(types(), - std::index_sequence(), - std::index_sequence(), - std::forward(matchfx), - L, - fxarity, - start, - std::forward(args)...); + if (!stack::stack_detail::check_types(args_list(), L, start, no_panic, tracking)) { + return overload_match_arity(types(), + std::index_sequence(), + std::index_sequence(), + std::forward(matchfx), + L, + fxarity, + start, + std::forward(args)...); } return matchfx(types(), meta::index_value(), return_types(), args_list(), L, fxarity, start, std::forward(args)...); } diff --git a/include/sol/config.hpp b/include/sol/config.hpp index 499ba775..e0019f83 100644 --- a/include/sol/config.hpp +++ b/include/sol/config.hpp @@ -191,7 +191,7 @@ // Interop allows userdata from external systems // with external memory layout and metatable names // to be registered. It costs something to perform -// the unqualified_checker / differentiation for sol2 usertypes versus +// the interop_checker / differentiation for sol2 usertypes versus // external ones however, so this is off by default #if !defined(SOL_ENABLE_INTEROP) // off by default here diff --git a/include/sol/stack.hpp b/include/sol/stack.hpp index 130d3d8d..b3903bb7 100644 --- a/include/sol/stack.hpp +++ b/include/sol/stack.hpp @@ -130,13 +130,14 @@ namespace sol { template inline decltype(auto) call(types, types ta, std::index_sequence tai, lua_State* L, int start, Fx&& fx, FxArgs&&... args) { static_assert(meta::all...>::value, "One of the arguments being bound is a move-only type, and it is not being taken by reference: this will break your code. Please take a reference and std::move it manually if this was your intention."); - argument_handler> handler{}; - multi_check(L, start, handler); + if constexpr (checkargs) { + argument_handler> handler{}; + multi_check(L, start, handler); + } record tracking{}; if constexpr (std::is_void_v) { eval(ta, tai, L, start, tracking, std::forward(fx), std::forward(args)...); } - else { return eval(ta, tai, L, start, tracking, std::forward(fx), std::forward(args)...); } diff --git a/include/sol/stack_check_get_unqualified.hpp b/include/sol/stack_check_get_unqualified.hpp index 124ec31a..66aa3e8f 100644 --- a/include/sol/stack_check_get_unqualified.hpp +++ b/include/sol/stack_check_get_unqualified.hpp @@ -58,11 +58,8 @@ namespace stack { } return stack_detail::unchecked_get(L, index, tracking); } - else if constexpr (std::is_same_v) { - return lua_toboolean(L, index) != 0; - } else if constexpr (std::is_integral_v && !std::is_same_v) { - #if SOL_LUA_VERSION >= 503 +#if SOL_LUA_VERSION >= 503 if (lua_isinteger(L, index) != 0) { tracking.use(1); return static_cast(lua_tointeger(L, index)); diff --git a/include/sol/stack_check_qualified.hpp b/include/sol/stack_check_qualified.hpp index 0d6090ab..d67c7f79 100644 --- a/include/sol/stack_check_qualified.hpp +++ b/include/sol/stack_check_qualified.hpp @@ -29,7 +29,7 @@ namespace sol { namespace stack { - template + template >, typename = void> struct qualified_checker { template static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { diff --git a/include/sol/stack_check_unqualified.hpp b/include/sol/stack_check_unqualified.hpp index 3386aaa1..a42ec6b7 100644 --- a/include/sol/stack_check_unqualified.hpp +++ b/include/sol/stack_check_unqualified.hpp @@ -86,7 +86,7 @@ namespace sol { namespace stack { } }; - template + template , typename = void> struct unqualified_checker { template static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { @@ -99,7 +99,10 @@ namespace sol { namespace stack { } return success; } - else if constexpr (std::is_integral_v && !std::is_same_v) { + else if constexpr (meta::any_same_v) { + return stack::check>(L, index, std::forward(handler), tracking); + } + else if constexpr (std::is_integral_v) { tracking.use(1); #if SOL_LUA_VERSION >= 503 #if defined(SOL_STRINGS_ARE_NUMBERS) && SOL_STRINGS_ARE_NUMBERS @@ -177,6 +180,9 @@ namespace sol { namespace stack { #endif // Strings are Numbers } else if constexpr(meta::any_same_v) { + (void)L; + (void)index; + (void)handler; tracking.use(0); return true; } @@ -471,7 +477,7 @@ namespace sol { namespace stack { template static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { const type indextype = type_of(L, index); - return check(L, index, indextype, handler, tracking); + return check(L, index, indextype, std::forward(handler), tracking); } }; diff --git a/include/sol/stack_core.hpp b/include/sol/stack_core.hpp index e1eaeba2..6ca48282 100644 --- a/include/sol/stack_core.hpp +++ b/include/sol/stack_core.hpp @@ -573,31 +573,35 @@ namespace sol { namespace stack { - template - struct extensible {}; - template struct field_getter; template struct probe_field_getter; + template struct field_setter; + template struct unqualified_getter; template struct qualified_getter; + template struct qualified_interop_getter; template struct unqualified_interop_getter; + template struct popper; + template struct unqualified_pusher; - template , typename C = void> + + template struct unqualified_checker; - template , typename C = void> + template struct qualified_checker; + template struct unqualified_check_getter; template @@ -707,19 +711,6 @@ namespace sol { template using strip_t = typename strip::type; - template - struct strip_extensible { - typedef T type; - }; - - template - struct strip_extensible> { - typedef T type; - }; - - template - using strip_extensible_t = typename strip_extensible::type; - template static int get_size_hint(C& c) { return static_cast(c.size()); @@ -767,7 +758,7 @@ namespace sol { (void)index; (void)unadjusted_pointer; (void)tracking; - using Ti = stack_detail::strip_extensible_t; + using Ti = stack_detail::strip_t; return std::pair{ false, nullptr }; } } @@ -1058,63 +1049,39 @@ namespace sol { namespace stack_detail { - template - struct check_types { - template - static bool check(types, lua_State* L, int firstargument, Handler&& handler, record& tracking) { - if (!stack::check(L, firstargument + tracking.used, handler, tracking)) - return false; - return check(types(), L, firstargument, std::forward(handler), tracking); - } - - template - static bool check(types<>, lua_State*, int, Handler&&, record&) { - return true; - } - }; - - template <> - struct check_types { - template - static bool check(types, lua_State*, int, Handler&&, record&) { - return true; - } - }; + template + inline bool check_types(lua_State* L, int firstargument, Handler&& handler, record& tracking) { + if (!stack::check(L, firstargument + tracking.used, handler, tracking)) + return false; + return check_types(L, firstargument, std::forward(handler), tracking); + } + template + static bool check_types(lua_State*, int, Handler&&, record&) { + return true; + } + template + bool check_types(types, lua_State* L, int index, Handler&& handler, record& tracking) { + return check_types(L, index, std::forward(handler), tracking); + } } // namespace stack_detail - template + template bool multi_check(lua_State* L, int index, Handler&& handler, record& tracking) { - return stack_detail::check_types{}.check(types...>(), L, index, std::forward(handler), tracking); + return stack_detail::check_types(L, index, std::forward(handler), tracking); } - template + template bool multi_check(lua_State* L, int index, Handler&& handler) { record tracking{}; - return multi_check(L, index, std::forward(handler), tracking); - } - - template - bool multi_check(lua_State* L, int index) { - auto handler = no_panic; - return multi_check(L, index, handler); - } - - template - bool multi_check(lua_State* L, int index, Handler&& handler, record& tracking) { - return multi_check(L, index, std::forward(handler), tracking); - } - - template - bool multi_check(lua_State* L, int index, Handler&& handler) { - return multi_check(L, index, std::forward(handler)); + return multi_check(L, index, std::forward(handler), tracking); } template bool multi_check(lua_State* L, int index) { - return multi_check(L, index); + return multi_check(L, index); } template diff --git a/include/sol/stack_field.hpp b/include/sol/stack_field.hpp index 873223cc..ea767f8a 100644 --- a/include/sol/stack_field.hpp +++ b/include/sol/stack_field.hpp @@ -45,6 +45,7 @@ namespace stack { (void)tableindex; } else if constexpr (std::is_same_v) { + (void)key; #if SOL_LUA_VERSION < 502 // Use lua_setfenv lua_getfenv(L, tableindex); @@ -56,6 +57,7 @@ namespace stack { #endif } else if constexpr (std::is_same_v) { + (void)key; if (lua_getmetatable(L, tableindex) == 0) push(L, lua_nil); } @@ -154,6 +156,7 @@ namespace stack { (void)tableindex; } else if constexpr (std::is_same_v) { + (void)key; push(L, std::forward(value)); lua_setmetatable(L, tableindex); } @@ -165,7 +168,7 @@ namespace stack { #if SOL_LUA_VERSION >= 502 else if constexpr (std::is_void_v>) { push(L, std::forward(value)); - lua_rawsetp(L, tableindex, key); + lua_rawsetp(L, tableindex, std::forward(key)); } #endif // Lua 5.2.x else { diff --git a/include/sol/stack_get_qualified.hpp b/include/sol/stack_get_qualified.hpp index 702f1882..2e8b517a 100644 --- a/include/sol/stack_get_qualified.hpp +++ b/include/sol/stack_get_qualified.hpp @@ -29,6 +29,10 @@ namespace sol { namespace stack { + // There are no more enable_ifs that can be used here, + // so this is just for posterity, I guess? + // maybe I'll fill this file in later. + } } // namespace sol::stack diff --git a/include/sol/stack_get_unqualified.hpp b/include/sol/stack_get_unqualified.hpp index f898a002..3c5e592c 100644 --- a/include/sol/stack_get_unqualified.hpp +++ b/include/sol/stack_get_unqualified.hpp @@ -163,8 +163,10 @@ namespace sol { namespace stack { struct qualified_getter { static decltype(auto) get(lua_State* L, int index, record& tracking) { using Tu = meta::unqualified_t; - if constexpr (!std::is_reference_v && is_container_v - && std::is_default_constructible_v && !is_lua_primitive_v && !is_transparent_argument_v) { + static constexpr bool is_userdata_of_some_kind + = !std::is_reference_v< + X> && is_container_v && std::is_default_constructible_v && !is_lua_primitive_v && !is_transparent_argument_v; + if constexpr (is_userdata_of_some_kind) { if (type_of(L, index) == type::userdata) { return static_cast(stack_detail::unchecked_unqualified_get(L, index, tracking)); } @@ -172,8 +174,8 @@ namespace sol { namespace stack { return stack_detail::unchecked_unqualified_get>(L, index, tracking); } } - else if constexpr (!std::is_reference_v && is_unique_usertype_v - && !std::is_void_v::template rebind_base>) { + else if constexpr (!std::is_reference_v< + X> && is_unique_usertype_v && !std::is_void_v::template rebind_base>) { using u_traits = unique_usertype_traits; using T = typename u_traits::type; using Real = typename u_traits::actual_type; @@ -220,7 +222,7 @@ namespace sol { namespace stack { } } else { - return stack::unqualified_get(L, index, tracking); + return stack_detail::unchecked_unqualified_get(L, index, tracking); } } }; diff --git a/include/sol/stack_pop.hpp b/include/sol/stack_pop.hpp index 880bd71c..f5790b5e 100644 --- a/include/sol/stack_pop.hpp +++ b/include/sol/stack_pop.hpp @@ -34,21 +34,19 @@ namespace stack { template struct popper { inline static decltype(auto) pop(lua_State* L) { - record tracking{}; -#ifdef __INTEL_COMPILER - auto&& r = get(L, -lua_size::value, tracking); -#else - decltype(auto) r = get(L, -lua_size::value, tracking); -#endif - lua_pop(L, tracking.used); - return r; + if constexpr (is_stack_based_v>) { + static_assert(!is_stack_based_v>, + "You cannot pop something that lives solely on the stack: it will not remain on the stack when popped and thusly will go out of " + "scope!"); + } + else { + record tracking{}; + decltype(auto) r = get(L, -lua_size::value, tracking); + lua_pop(L, tracking.used); + return r; + } } }; - - template - struct popper>::value>> { - static_assert(meta::neg>>::value, "You cannot pop something that lives solely on the stack: it will not remain on the stack when popped and thusly will go out of scope!"); - }; } } // namespace sol::stack diff --git a/include/sol/stack_push.hpp b/include/sol/stack_push.hpp index 78d52ea2..4e5a43e2 100644 --- a/include/sol/stack_push.hpp +++ b/include/sol/stack_push.hpp @@ -64,8 +64,13 @@ namespace sol { template int msvc_is_ass_with_if_constexpr_push_enum(std::true_type, lua_State* L, const T& value) { - if constexpr (std::is_same_v, char>) { - return stack::push(L, static_cast(value)); + if constexpr (meta::any_same_v, char/*, char8_t*/, char16_t, char32_t>) { + if constexpr (std::is_signed_v) { + return stack::push(L, static_cast(value)); + } + else { + return stack::push(L, static_cast(value)); + } } else { return stack::push(L, static_cast>(value)); @@ -130,6 +135,7 @@ namespace sol { template static int push(lua_State* L, Arg&& arg, Args&&... args) { if constexpr (std::is_same_v, detail::with_function_tag>) { + (void)arg; return push_fx(L, std::forward(args)...); } else { @@ -168,6 +174,7 @@ namespace sol { template static int push(lua_State* L, Arg&& arg, Args&&... args) { if constexpr (std::is_same_v, detail::with_function_tag>) { + (void)arg; return push_fx(L, std::forward(args)...); } else { @@ -309,11 +316,15 @@ namespace sol { template struct unqualified_pusher> { using has_kvp = meta::has_key_value_pair>>; - + static int push(lua_State* L, const T& tablecont) { return push(has_kvp(), std::false_type(), L, tablecont); } + static int push(lua_State* L, const T& tablecont, nested_tag_t) { + return push(has_kvp(), std::true_type(), L, tablecont); + } + static int push(std::true_type, lua_State* L, const T& tablecont) { return push(has_kvp(), std::true_type(), L, tablecont); } @@ -400,7 +411,7 @@ namespace sol { static int push(lua_State* L, const T& tablecont) { using inner_t = std::remove_pointer_t>; if constexpr (is_container_v) { - return stack::push>(L, tablecont); + return stack::push>(L, tablecont, nested_tag); } else { return stack::push(L, tablecont); @@ -596,6 +607,7 @@ namespace sol { return push_with(L, name, std::forward(args)...); } else if constexpr (std::is_same_v, no_metatable_t>) { + (void)arg; const auto name = &usertype_traits>::user_gc_metatable()[0]; return push_with(L, name, std::forward(args)...); } diff --git a/include/sol/types.hpp b/include/sol/types.hpp index 51c2fc41..6248ebc8 100644 --- a/include/sol/types.hpp +++ b/include/sol/types.hpp @@ -454,6 +454,9 @@ namespace sol { } }; + struct nested_tag_t {}; + constexpr inline nested_tag_t nested_tag{}; + template as_table_t as_table_ref(T&& container) { return as_table_t(std::forward(container)); diff --git a/single/include/sol/forward.hpp b/single/include/sol/forward.hpp index 39dfd145..8540795c 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-03-10 01:57:28.833449 UTC -// This header was generated with sol v3.0.0 (revision b6f4093) +// Generated 2019-03-10 15:09:32.665841 UTC +// This header was generated with sol v3.0.0 (revision ee13a78) // 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 d800b1dc..3112ecb2 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-03-10 01:57:28.472452 UTC -// This header was generated with sol v3.0.0 (revision b6f4093) +// Generated 2019-03-10 15:09:32.355673 UTC +// This header was generated with sol v3.0.0 (revision ee13a78) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -6449,6 +6449,9 @@ namespace sol { } }; + struct nested_tag_t {}; + constexpr inline nested_tag_t nested_tag{}; + template as_table_t as_table_ref(T&& container) { return as_table_t(std::forward(container)); @@ -9433,31 +9436,35 @@ namespace sol { namespace stack { - template - struct extensible {}; - template struct field_getter; template struct probe_field_getter; + template struct field_setter; + template struct unqualified_getter; template struct qualified_getter; + template struct qualified_interop_getter; template struct unqualified_interop_getter; + template struct popper; + template struct unqualified_pusher; - template , typename C = void> + + template struct unqualified_checker; - template , typename C = void> + template struct qualified_checker; + template struct unqualified_check_getter; template @@ -9566,19 +9573,6 @@ namespace sol { template using strip_t = typename strip::type; - template - struct strip_extensible { - typedef T type; - }; - - template - struct strip_extensible> { - typedef T type; - }; - - template - using strip_extensible_t = typename strip_extensible::type; - template static int get_size_hint(C& c) { return static_cast(c.size()); @@ -9626,7 +9620,7 @@ namespace sol { (void)index; (void)unadjusted_pointer; (void)tracking; - using Ti = stack_detail::strip_extensible_t; + using Ti = stack_detail::strip_t; return std::pair{ false, nullptr }; } } @@ -9917,61 +9911,39 @@ namespace sol { namespace stack_detail { - template - struct check_types { - template - static bool check(types, lua_State* L, int firstargument, Handler&& handler, record& tracking) { - if (!stack::check(L, firstargument + tracking.used, handler, tracking)) - return false; - return check(types(), L, firstargument, std::forward(handler), tracking); - } + template + inline bool check_types(lua_State* L, int firstargument, Handler&& handler, record& tracking) { + if (!stack::check(L, firstargument + tracking.used, handler, tracking)) + return false; + return check_types(L, firstargument, std::forward(handler), tracking); + } - template - static bool check(types<>, lua_State*, int, Handler&&, record&) { - return true; - } - }; + template + static bool check_types(lua_State*, int, Handler&&, record&) { + return true; + } - template <> - struct check_types { - template - static bool check(types, lua_State*, int, Handler&&, record&) { - return true; - } - }; + template + bool check_types(types, lua_State* L, int index, Handler&& handler, record& tracking) { + return check_types(L, index, std::forward(handler), tracking); + } } // namespace stack_detail - template + template bool multi_check(lua_State* L, int index, Handler&& handler, record& tracking) { - return stack_detail::check_types{}.check(types...>(), L, index, std::forward(handler), tracking); + return stack_detail::check_types(L, index, std::forward(handler), tracking); } - template + template bool multi_check(lua_State* L, int index, Handler&& handler) { record tracking{}; - return multi_check(L, index, std::forward(handler), tracking); - } - - template - bool multi_check(lua_State* L, int index) { - auto handler = no_panic; - return multi_check(L, index, handler); - } - - template - bool multi_check(lua_State* L, int index, Handler&& handler, record& tracking) { - return multi_check(L, index, std::forward(handler), tracking); - } - - template - bool multi_check(lua_State* L, int index, Handler&& handler) { - return multi_check(L, index, std::forward(handler)); + return multi_check(L, index, std::forward(handler), tracking); } template bool multi_check(lua_State* L, int index) { - return multi_check(L, index); + return multi_check(L, index); } template @@ -10335,7 +10307,7 @@ namespace sol { namespace stack { } }; - template + template , typename = void> struct unqualified_checker { template static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { @@ -10348,7 +10320,10 @@ namespace sol { namespace stack { } return success; } - else if constexpr (std::is_integral_v && !std::is_same_v) { + else if constexpr (meta::any_same_v) { + return stack::check>(L, index, std::forward(handler), tracking); + } + else if constexpr (std::is_integral_v) { tracking.use(1); #if SOL_LUA_VERSION >= 503 #if defined(SOL_STRINGS_ARE_NUMBERS) && SOL_STRINGS_ARE_NUMBERS @@ -10426,6 +10401,9 @@ namespace sol { namespace stack { #endif // Strings are Numbers } else if constexpr(meta::any_same_v) { + (void)L; + (void)index; + (void)handler; tracking.use(0); return true; } @@ -10720,7 +10698,7 @@ namespace sol { namespace stack { template static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { const type indextype = type_of(L, index); - return check(L, index, indextype, handler, tracking); + return check(L, index, indextype, std::forward(handler), tracking); } }; @@ -10825,7 +10803,7 @@ namespace sol { namespace stack { namespace sol { namespace stack { - template + template >, typename = void> struct qualified_checker { template static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { @@ -11345,8 +11323,10 @@ namespace sol { namespace stack { struct qualified_getter { static decltype(auto) get(lua_State* L, int index, record& tracking) { using Tu = meta::unqualified_t; - if constexpr (!std::is_reference_v && is_container_v - && std::is_default_constructible_v && !is_lua_primitive_v && !is_transparent_argument_v) { + static constexpr bool is_userdata_of_some_kind + = !std::is_reference_v< + X> && is_container_v && std::is_default_constructible_v && !is_lua_primitive_v && !is_transparent_argument_v; + if constexpr (is_userdata_of_some_kind) { if (type_of(L, index) == type::userdata) { return static_cast(stack_detail::unchecked_unqualified_get(L, index, tracking)); } @@ -11354,8 +11334,8 @@ namespace sol { namespace stack { return stack_detail::unchecked_unqualified_get>(L, index, tracking); } } - else if constexpr (!std::is_reference_v && is_unique_usertype_v - && !std::is_void_v::template rebind_base>) { + else if constexpr (!std::is_reference_v< + X> && is_unique_usertype_v && !std::is_void_v::template rebind_base>) { using u_traits = unique_usertype_traits; using T = typename u_traits::type; using Real = typename u_traits::actual_type; @@ -11402,7 +11382,7 @@ namespace sol { namespace stack { } } else { - return stack::unqualified_get(L, index, tracking); + return stack_detail::unchecked_unqualified_get(L, index, tracking); } } }; @@ -12200,6 +12180,10 @@ namespace sol { namespace stack { namespace sol { namespace stack { + // There are no more enable_ifs that can be used here, + // so this is just for posterity, I guess? + // maybe I'll fill this file in later. + } } // namespace sol::stack @@ -12235,11 +12219,8 @@ namespace stack { } return stack_detail::unchecked_get(L, index, tracking); } - else if constexpr (std::is_same_v) { - return lua_toboolean(L, index) != 0; - } else if constexpr (std::is_integral_v && !std::is_same_v) { - #if SOL_LUA_VERSION >= 503 +#if SOL_LUA_VERSION >= 503 if (lua_isinteger(L, index) != 0) { tracking.use(1); return static_cast(lua_tointeger(L, index)); @@ -12458,8 +12439,13 @@ namespace sol { template int msvc_is_ass_with_if_constexpr_push_enum(std::true_type, lua_State* L, const T& value) { - if constexpr (std::is_same_v, char>) { - return stack::push(L, static_cast(value)); + if constexpr (meta::any_same_v, char/*, char8_t*/, char16_t, char32_t>) { + if constexpr (std::is_signed_v) { + return stack::push(L, static_cast(value)); + } + else { + return stack::push(L, static_cast(value)); + } } else { return stack::push(L, static_cast>(value)); @@ -12524,6 +12510,7 @@ namespace sol { template static int push(lua_State* L, Arg&& arg, Args&&... args) { if constexpr (std::is_same_v, detail::with_function_tag>) { + (void)arg; return push_fx(L, std::forward(args)...); } else { @@ -12562,6 +12549,7 @@ namespace sol { template static int push(lua_State* L, Arg&& arg, Args&&... args) { if constexpr (std::is_same_v, detail::with_function_tag>) { + (void)arg; return push_fx(L, std::forward(args)...); } else { @@ -12703,11 +12691,15 @@ namespace sol { template struct unqualified_pusher> { using has_kvp = meta::has_key_value_pair>>; - + static int push(lua_State* L, const T& tablecont) { return push(has_kvp(), std::false_type(), L, tablecont); } + static int push(lua_State* L, const T& tablecont, nested_tag_t) { + return push(has_kvp(), std::true_type(), L, tablecont); + } + static int push(std::true_type, lua_State* L, const T& tablecont) { return push(has_kvp(), std::true_type(), L, tablecont); } @@ -12794,7 +12786,7 @@ namespace sol { static int push(lua_State* L, const T& tablecont) { using inner_t = std::remove_pointer_t>; if constexpr (is_container_v) { - return stack::push>(L, tablecont); + return stack::push>(L, tablecont, nested_tag); } else { return stack::push(L, tablecont); @@ -12990,6 +12982,7 @@ namespace sol { return push_with(L, name, std::forward(args)...); } else if constexpr (std::is_same_v, no_metatable_t>) { + (void)arg; const auto name = &usertype_traits>::user_gc_metatable()[0]; return push_with(L, name, std::forward(args)...); } @@ -13581,21 +13574,19 @@ namespace stack { template struct popper { inline static decltype(auto) pop(lua_State* L) { - record tracking{}; -#ifdef __INTEL_COMPILER - auto&& r = get(L, -lua_size::value, tracking); -#else - decltype(auto) r = get(L, -lua_size::value, tracking); -#endif - lua_pop(L, tracking.used); - return r; + if constexpr (is_stack_based_v>) { + static_assert(!is_stack_based_v>, + "You cannot pop something that lives solely on the stack: it will not remain on the stack when popped and thusly will go out of " + "scope!"); + } + else { + record tracking{}; + decltype(auto) r = get(L, -lua_size::value, tracking); + lua_pop(L, tracking.used); + return r; + } } }; - - template - struct popper>::value>> { - static_assert(meta::neg>>::value, "You cannot pop something that lives solely on the stack: it will not remain on the stack when popped and thusly will go out of scope!"); - }; } } // namespace sol::stack @@ -13619,6 +13610,7 @@ namespace stack { (void)tableindex; } else if constexpr (std::is_same_v) { + (void)key; #if SOL_LUA_VERSION < 502 // Use lua_setfenv lua_getfenv(L, tableindex); @@ -13630,6 +13622,7 @@ namespace stack { #endif } else if constexpr (std::is_same_v) { + (void)key; if (lua_getmetatable(L, tableindex) == 0) push(L, lua_nil); } @@ -13728,6 +13721,7 @@ namespace stack { (void)tableindex; } else if constexpr (std::is_same_v) { + (void)key; push(L, std::forward(value)); lua_setmetatable(L, tableindex); } @@ -13739,7 +13733,7 @@ namespace stack { #if SOL_LUA_VERSION >= 502 else if constexpr (std::is_void_v>) { push(L, std::forward(value)); - lua_rawsetp(L, tableindex, key); + lua_rawsetp(L, tableindex, std::forward(key)); } #endif // Lua 5.2.x else { @@ -13977,13 +13971,14 @@ namespace sol { template inline decltype(auto) call(types, types ta, std::index_sequence tai, lua_State* L, int start, Fx&& fx, FxArgs&&... args) { static_assert(meta::all...>::value, "One of the arguments being bound is a move-only type, and it is not being taken by reference: this will break your code. Please take a reference and std::move it manually if this was your intention."); - argument_handler> handler{}; - multi_check(L, start, handler); + if constexpr (checkargs) { + argument_handler> handler{}; + multi_check(L, start, handler); + } record tracking{}; if constexpr (std::is_void_v) { eval(ta, tai, L, start, tracking, std::forward(fx), std::forward(args)...); } - else { return eval(ta, tai, L, start, tracking, std::forward(fx), std::forward(args)...); } @@ -15609,8 +15604,7 @@ namespace sol { } } stack::record tracking{}; - stack::stack_detail::check_types ct{}; - if (!ct.check(args_list(), L, start, no_panic, tracking)) { + if (!stack::stack_detail::check_types(args_list(), L, start, no_panic, tracking)) { return overload_match_arity(types(), std::index_sequence(), std::index_sequence(), @@ -15700,16 +15694,15 @@ namespace sol { } } stack::record tracking{}; - stack::stack_detail::check_types ct{}; - if (!ct.check(args_list(), L, start, no_panic, tracking)) { - return overload_match_arity(types(), - std::index_sequence(), - std::index_sequence(), - std::forward(matchfx), - L, - fxarity, - start, - std::forward(args)...); + if (!stack::stack_detail::check_types(args_list(), L, start, no_panic, tracking)) { + return overload_match_arity(types(), + std::index_sequence(), + std::index_sequence(), + std::forward(matchfx), + L, + fxarity, + start, + std::forward(args)...); } return matchfx(types(), meta::index_value(), return_types(), args_list(), L, fxarity, start, std::forward(args)...); } diff --git a/tests/runtime_tests/source/container_table.cpp b/tests/runtime_tests/source/container_table.cpp index e820f591..7941cef7 100644 --- a/tests/runtime_tests/source/container_table.cpp +++ b/tests/runtime_tests/source/container_table.cpp @@ -284,9 +284,9 @@ TEST_CASE("containers/deeply nested", "make sure nested works for deeply-nested list.push_back(info_t{ { "a", "b" } }); } - sol::nested getList() { - return sol::nested(list); - }; + sol::nested getList() { + return sol::nested(list); + } }; sol::state lua; diff --git a/tests/runtime_tests/source/customizations_private.cpp b/tests/runtime_tests/source/customizations_private.cpp index d3c10907..ac69887c 100644 --- a/tests/runtime_tests/source/customizations_private.cpp +++ b/tests/runtime_tests/source/customizations_private.cpp @@ -121,7 +121,7 @@ TEST_CASE("customization/split struct", "using the old customization points to h sol::state lua; // Create a pass-through style of function - auto result1 = lua.safe_script("function f ( a, b, c ) return a + c, b end"); + auto result1 = lua.safe_script("function f ( a, b, c ) return a + c, b end", sol::script_pass_on_error); REQUIRE(result1.valid()); lua.set_function("g", [](int a, bool b, int c, double d) { return std::make_tuple(a + c, b, d + 2.5); }); @@ -130,12 +130,12 @@ TEST_CASE("customization/split struct", "using the old customization points to h sol::function g = lua["g"]; two_things thingsf = f(two_things{ 24, true }, 1); - two_things thingsg; - double d; - sol::tie(thingsg, d) = g(two_things{ 25, false }, 2, 34.0); REQUIRE(thingsf.a == 25); REQUIRE(thingsf.b); + two_things thingsg; + double d; + sol::tie(thingsg, d) = g(two_things{ 25, false }, 2, 34.0); REQUIRE(thingsg.a == 27); REQUIRE_FALSE(thingsg.b); REQUIRE(d == 36.5); diff --git a/tests/runtime_tests/source/strings.cpp b/tests/runtime_tests/source/strings.cpp index fedd575d..fbede35a 100644 --- a/tests/runtime_tests/source/strings.cpp +++ b/tests/runtime_tests/source/strings.cpp @@ -68,65 +68,83 @@ TEST_CASE("stack/strings", "test that strings can be roundtripped") { lua["utf32"] = utf32str; lua["wide"] = widestr; - std::string utf8_to_utf8 = lua["utf8"]; - std::string utf16_to_utf8 = lua["utf16"]; - std::string utf32_to_utf8 = lua["utf32"]; - std::string wide_to_utf8 = lua["wide"]; + SECTION("to_utf8") { + std::string utf8_to_utf8 = lua["utf8"]; + std::string utf16_to_utf8 = lua["utf16"]; + std::string utf32_to_utf8 = lua["utf32"]; + std::string wide_to_utf8 = lua["wide"]; - REQUIRE(utf8_to_utf8 == utf8str_s); - REQUIRE(utf16_to_utf8 == utf8str_s); - REQUIRE(utf32_to_utf8 == utf8str_s); - REQUIRE(wide_to_utf8 == utf8str_s); + REQUIRE(utf8_to_utf8 == utf8str_s); + REQUIRE(utf16_to_utf8 == utf8str_s); + REQUIRE(utf32_to_utf8 == utf8str_s); + REQUIRE(wide_to_utf8 == utf8str_s); + } + SECTION("to_wide") { + std::wstring utf8_to_wide = lua["utf8"]; + std::wstring utf16_to_wide = lua["utf16"]; + std::wstring utf32_to_wide = lua["utf32"]; + std::wstring wide_to_wide = lua["wide"]; - std::wstring utf8_to_wide = lua["utf8"]; - std::wstring utf16_to_wide = lua["utf16"]; - std::wstring utf32_to_wide = lua["utf32"]; - std::wstring wide_to_wide = lua["wide"]; + REQUIRE(utf8_to_wide == widestr_s); + REQUIRE(utf16_to_wide == widestr_s); + REQUIRE(utf32_to_wide == widestr_s); + REQUIRE(wide_to_wide == widestr_s); + } + SECTION("to_utf16") { + std::u16string utf8_to_utf16 = lua["utf8"]; + std::u16string utf16_to_utf16 = lua["utf16"]; + std::u16string utf32_to_utf16 = lua["utf32"]; + std::u16string wide_to_utf16 = lua["wide"]; - REQUIRE(utf8_to_wide == widestr_s); - REQUIRE(utf16_to_wide == widestr_s); - REQUIRE(utf32_to_wide == widestr_s); - REQUIRE(wide_to_wide == widestr_s); + REQUIRE(utf8_to_utf16 == utf16str_s); + REQUIRE(utf16_to_utf16 == utf16str_s); + REQUIRE(utf32_to_utf16 == utf16str_s); + REQUIRE(wide_to_utf16 == utf16str_s); + } + SECTION("to_utf32") { + std::u32string utf8_to_utf32 = lua["utf8"]; + std::u32string utf16_to_utf32 = lua["utf16"]; + std::u32string utf32_to_utf32 = lua["utf32"]; + std::u32string wide_to_utf32 = lua["wide"]; - std::u16string utf8_to_utf16 = lua["utf8"]; - std::u16string utf16_to_utf16 = lua["utf16"]; - std::u16string utf32_to_utf16 = lua["utf32"]; - std::u16string wide_to_utf16 = lua["wide"]; + REQUIRE(utf8_to_utf32 == utf32str_s); + REQUIRE(utf16_to_utf32 == utf32str_s); + REQUIRE(utf32_to_utf32 == utf32str_s); + REQUIRE(wide_to_utf32 == utf32str_s); + } + SECTION("to_char32_t") { + char32_t utf8_to_char32 = lua["utf8"]; + char32_t utf16_to_char32 = lua["utf16"]; + char32_t utf32_to_char32 = lua["utf32"]; + char32_t wide_to_char32 = lua["wide"]; - REQUIRE(utf8_to_utf16 == utf16str_s); - REQUIRE(utf16_to_utf16 == utf16str_s); - REQUIRE(utf32_to_utf16 == utf16str_s); - REQUIRE(wide_to_utf16 == utf16str_s); + REQUIRE(utf8_to_char32 == utf32str[0]); + REQUIRE(utf16_to_char32 == utf32str[0]); + REQUIRE(utf32_to_char32 == utf32str[0]); + REQUIRE(wide_to_char32 == utf32str[0]); + } + SECTION("to_char16_t") { + char16_t utf8_to_char16 = lua["utf8"]; + char16_t utf16_to_char16 = lua["utf16"]; + char16_t utf32_to_char16 = lua["utf32"]; + char16_t wide_to_char16 = lua["wide"]; - std::u32string utf8_to_utf32 = lua["utf8"]; - std::u32string utf16_to_utf32 = lua["utf16"]; - std::u32string utf32_to_utf32 = lua["utf32"]; - std::u32string wide_to_utf32 = lua["wide"]; + REQUIRE(utf8_to_char16 == utf16str[0]); + REQUIRE(utf16_to_char16 == utf16str[0]); + REQUIRE(utf32_to_char16 == utf16str[0]); + REQUIRE(wide_to_char16 == utf16str[0]); + } + SECTION("to_char") { + char utf8_to_char = lua["utf8"].get(); + char utf16_to_char = lua["utf16"].get(); + char utf32_to_char = lua["utf32"].get(); + char wide_to_char = lua["wide"].get(); - REQUIRE(utf8_to_utf32 == utf32str_s); - REQUIRE(utf16_to_utf32 == utf32str_s); - REQUIRE(utf32_to_utf32 == utf32str_s); - REQUIRE(wide_to_utf32 == utf32str_s); - - char32_t utf8_to_char32 = lua["utf8"]; - char32_t utf16_to_char32 = lua["utf16"]; - char32_t utf32_to_char32 = lua["utf32"]; - char32_t wide_to_char32 = lua["wide"]; - - REQUIRE(utf8_to_char32 == utf32str[0]); - REQUIRE(utf16_to_char32 == utf32str[0]); - REQUIRE(utf32_to_char32 == utf32str[0]); - REQUIRE(wide_to_char32 == utf32str[0]); - - char16_t utf8_to_char16 = lua["utf8"]; - char16_t utf16_to_char16 = lua["utf16"]; - char16_t utf32_to_char16 = lua["utf32"]; - char16_t wide_to_char16 = lua["wide"]; - - REQUIRE(utf8_to_char16 == utf16str[0]); - REQUIRE(utf16_to_char16 == utf16str[0]); - REQUIRE(utf32_to_char16 == utf16str[0]); - REQUIRE(wide_to_char16 == utf16str[0]); + REQUIRE(utf8_to_char == utf8str[0]); + REQUIRE(utf16_to_char == utf8str[0]); + REQUIRE(utf32_to_char == utf8str[0]); + REQUIRE(wide_to_char == utf8str[0]); + } } TEST_CASE("detail/demangling", "test some basic demangling cases") {