diff --git a/sol/function_types_core.hpp b/sol/function_types_core.hpp index 50bffe8f..f00ed631 100644 --- a/sol/function_types_core.hpp +++ b/sol/function_types_core.hpp @@ -66,6 +66,7 @@ struct functor { typedef callable_traits traits_type; typedef typename traits_type::args_type args_type; typedef typename traits_type::return_type return_type; + static const std::size_t arity = traits_type::arity; T* item; Func invocation; @@ -100,6 +101,7 @@ struct functor::va typedef callable_traits traits_type; typedef typename traits_type::args_type args_type; typedef typename traits_type::return_type return_type; + static const std::size_t arity = traits_type::arity; T* item; Func invocation; @@ -132,6 +134,7 @@ struct functor::value || std::i typedef callable_traits traits_type; typedef pop_front_type_t args_type; typedef typename traits_type::return_type return_type; + static const std::size_t arity = traits_type::arity; typedef std::tuple_element_t<0, typename traits_type::args_tuple_type> Arg0; typedef std::conditional_t::value || std::is_class::value, Func, std::add_pointer_t> function_type; static_assert(std::is_base_of>, T>::value, "Any non-member-function must have a first argument which is covariant with the desired userdata type."); diff --git a/sol/function_types_overload.hpp b/sol/function_types_overload.hpp index 24e0de70..3669ba54 100644 --- a/sol/function_types_overload.hpp +++ b/sol/function_types_overload.hpp @@ -28,6 +28,16 @@ namespace sol { namespace detail { +template +struct overload_traits : function_traits {}; + +template +struct overload_traits> { + typedef typename functor::args_type args_type; + typedef typename functor::return_type return_type; + static const std::size_t arity = functor::arity; +}; + template inline int overload_match_arity(types<>, std::index_sequence<>, std::index_sequence, Match&&, lua_State*, int, int, Args&&...) { throw error("no matching function call takes this number of arguments and the specified types"); @@ -35,9 +45,9 @@ inline int overload_match_arity(types<>, std::index_sequence<>, std::index_seque template inline int overload_match_arity(types, std::index_sequence, std::index_sequence, Match&& matchfx, lua_State* L, int fxarity, int start, Args&&... args) { - typedef function_traits traits; - typedef tuple_types::return_type> return_types; - typedef typename function_traits::args_type args_type; + typedef overload_traits> traits; + typedef tuple_types return_types; + typedef typename traits::args_type args_type; typedef typename args_type::indices args_indices; // compile-time eliminate any functions that we know ahead of time are of improper arity if (find_in_pack_v, Index...>::value) { @@ -96,7 +106,7 @@ struct overloaded_function : base_function { template struct usertype_overloaded_function : base_function { - typedef std::tuple...> overload_list; + typedef std::tuple>>...> overload_list; typedef std::index_sequence_for indices; overload_list overloads; @@ -116,7 +126,7 @@ struct usertype_overloaded_function : base_function { virtual int operator()(lua_State* L) override { auto mfx = [&](auto&&... args){ return this->call(std::forward(args)...); }; - return overload_match(mfx, L, 2); + return overload_match>>...>(mfx, L, 2); } };