2020-08-10 05:17:06 +08:00
|
|
|
// sol3
|
2017-12-20 17:58:32 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
// The MIT License (MIT)
|
2016-06-04 09:40:23 +08:00
|
|
|
|
2021-03-06 14:03:23 +08:00
|
|
|
// Copyright (c) 2013-2021 Rapptz, ThePhD and contributors
|
2016-06-04 09:40:23 +08:00
|
|
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
// this software and associated documentation files (the "Software"), to deal in
|
|
|
|
// the Software without restriction, including without limitation the rights to
|
|
|
|
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
// the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
// subject to the following conditions:
|
|
|
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in all
|
|
|
|
// copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
#ifndef SOL_WRAPPER_HPP
|
|
|
|
#define SOL_WRAPPER_HPP
|
|
|
|
|
2020-08-10 05:17:06 +08:00
|
|
|
#include <sol/types.hpp>
|
2016-06-04 09:40:23 +08:00
|
|
|
|
|
|
|
namespace sol {
|
|
|
|
|
2018-03-19 11:41:03 +08:00
|
|
|
namespace detail {
|
|
|
|
template <typename T>
|
2019-03-15 04:15:43 +08:00
|
|
|
using array_return_type = meta::conditional_t<std::is_array<T>::value, std::add_lvalue_reference_t<T>, T>;
|
2018-03-19 11:41:03 +08:00
|
|
|
}
|
|
|
|
|
2016-06-04 09:40:23 +08:00
|
|
|
template <typename F, typename = void>
|
|
|
|
struct wrapper {
|
2017-08-25 02:39:02 +08:00
|
|
|
typedef lua_bind_traits<meta::unqualified_t<F>> traits_type;
|
2016-06-04 09:40:23 +08:00
|
|
|
typedef typename traits_type::args_list args_list;
|
|
|
|
typedef typename traits_type::args_list free_args_list;
|
|
|
|
typedef typename traits_type::returns_list returns_list;
|
|
|
|
|
2016-06-18 15:32:54 +08:00
|
|
|
template <typename... Args>
|
|
|
|
static decltype(auto) call(F& f, Args&&... args) {
|
|
|
|
return f(std::forward<Args>(args)...);
|
2016-06-04 09:40:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct caller {
|
2016-06-18 15:32:54 +08:00
|
|
|
template <typename... Args>
|
|
|
|
decltype(auto) operator()(F& fx, Args&&... args) const {
|
|
|
|
return call(fx, std::forward<Args>(args)...);
|
2016-06-04 09:40:23 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename F>
|
2017-09-13 14:46:56 +08:00
|
|
|
struct wrapper<F, std::enable_if_t<std::is_function<std::remove_pointer_t<meta::unqualified_t<F>>>::value>> {
|
|
|
|
typedef lua_bind_traits<std::remove_pointer_t<meta::unqualified_t<F>>> traits_type;
|
2016-06-04 09:40:23 +08:00
|
|
|
typedef typename traits_type::args_list args_list;
|
|
|
|
typedef typename traits_type::args_list free_args_list;
|
|
|
|
typedef typename traits_type::returns_list returns_list;
|
|
|
|
|
|
|
|
template <F fx, typename... Args>
|
|
|
|
static decltype(auto) invoke(Args&&... args) {
|
|
|
|
return fx(std::forward<Args>(args)...);
|
|
|
|
}
|
|
|
|
|
2016-06-18 15:32:54 +08:00
|
|
|
template <typename... Args>
|
|
|
|
static decltype(auto) call(F& fx, Args&&... args) {
|
2016-06-04 09:40:23 +08:00
|
|
|
return fx(std::forward<Args>(args)...);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct caller {
|
2016-06-18 15:32:54 +08:00
|
|
|
template <typename... Args>
|
|
|
|
decltype(auto) operator()(F& fx, Args&&... args) const {
|
|
|
|
return call(fx, std::forward<Args>(args)...);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <F fx>
|
|
|
|
struct invoker {
|
|
|
|
template <typename... Args>
|
|
|
|
decltype(auto) operator()(Args&&... args) const {
|
|
|
|
return invoke<fx>(std::forward<Args>(args)...);
|
2016-06-04 09:40:23 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename F>
|
|
|
|
struct wrapper<F, std::enable_if_t<std::is_member_object_pointer<meta::unqualified_t<F>>::value>> {
|
2017-09-13 14:46:56 +08:00
|
|
|
typedef lua_bind_traits<meta::unqualified_t<F>> traits_type;
|
2016-06-04 09:40:23 +08:00
|
|
|
typedef typename traits_type::object_type object_type;
|
|
|
|
typedef typename traits_type::return_type return_type;
|
|
|
|
typedef typename traits_type::args_list args_list;
|
|
|
|
typedef types<object_type&, return_type> free_args_list;
|
|
|
|
typedef typename traits_type::returns_list returns_list;
|
|
|
|
|
2017-05-29 22:32:37 +08:00
|
|
|
template <F fx>
|
2018-03-19 11:41:03 +08:00
|
|
|
static auto call(object_type& mem) -> detail::array_return_type<decltype(mem.*fx)> {
|
2017-05-29 22:32:37 +08:00
|
|
|
return mem.*fx;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <F fx, typename Arg, typename... Args>
|
|
|
|
static decltype(auto) invoke(object_type& mem, Arg&& arg, Args&&...) {
|
|
|
|
return mem.*fx = std::forward<Arg>(arg);
|
2016-06-04 09:40:23 +08:00
|
|
|
}
|
|
|
|
|
2016-07-10 01:38:55 +08:00
|
|
|
template <typename Fx>
|
2018-03-19 11:41:03 +08:00
|
|
|
static auto call(Fx&& fx, object_type& mem) -> detail::array_return_type<decltype(mem.*fx)> {
|
|
|
|
return mem.*fx;
|
2016-06-04 09:40:23 +08:00
|
|
|
}
|
|
|
|
|
2016-07-10 01:38:55 +08:00
|
|
|
template <typename Fx, typename Arg, typename... Args>
|
|
|
|
static void call(Fx&& fx, object_type& mem, Arg&& arg, Args&&...) {
|
2019-02-11 04:02:40 +08:00
|
|
|
using actual_type = meta::unqualified_t<detail::array_return_type<decltype(mem.*fx)>>;
|
|
|
|
if constexpr (std::is_array_v<actual_type>) {
|
|
|
|
using std::cbegin;
|
2020-08-10 05:17:06 +08:00
|
|
|
using std::cend;
|
2019-02-11 04:02:40 +08:00
|
|
|
auto first = cbegin(arg);
|
|
|
|
auto last = cend(arg);
|
|
|
|
for (std::size_t i = 0; first != last; ++i, ++first) {
|
|
|
|
(mem.*fx)[i] = *first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
(mem.*fx) = std::forward<Arg>(arg);
|
|
|
|
}
|
2016-06-04 09:40:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct caller {
|
2016-07-10 01:38:55 +08:00
|
|
|
template <typename Fx, typename... Args>
|
|
|
|
decltype(auto) operator()(Fx&& fx, object_type& mem, Args&&... args) const {
|
|
|
|
return call(std::forward<Fx>(fx), mem, std::forward<Args>(args)...);
|
2016-06-18 15:32:54 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <F fx>
|
|
|
|
struct invoker {
|
|
|
|
template <typename... Args>
|
|
|
|
decltype(auto) operator()(Args&&... args) const {
|
|
|
|
return invoke<fx>(std::forward<Args>(args)...);
|
2016-06-04 09:40:23 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename F, typename R, typename O, typename... FArgs>
|
|
|
|
struct member_function_wrapper {
|
|
|
|
typedef O object_type;
|
|
|
|
typedef lua_bind_traits<F> traits_type;
|
|
|
|
typedef typename traits_type::args_list args_list;
|
|
|
|
typedef types<object_type&, FArgs...> free_args_list;
|
|
|
|
typedef meta::tuple_types<R> returns_list;
|
|
|
|
|
|
|
|
template <F fx, typename... Args>
|
2016-06-08 08:32:10 +08:00
|
|
|
static R invoke(O& mem, Args&&... args) {
|
2016-06-04 09:40:23 +08:00
|
|
|
return (mem.*fx)(std::forward<Args>(args)...);
|
|
|
|
}
|
|
|
|
|
2016-07-10 01:38:55 +08:00
|
|
|
template <typename Fx, typename... Args>
|
|
|
|
static R call(Fx&& fx, O& mem, Args&&... args) {
|
2016-06-04 09:40:23 +08:00
|
|
|
return (mem.*fx)(std::forward<Args>(args)...);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct caller {
|
2016-07-10 01:38:55 +08:00
|
|
|
template <typename Fx, typename... Args>
|
|
|
|
decltype(auto) operator()(Fx&& fx, O& mem, Args&&... args) const {
|
|
|
|
return call(std::forward<Fx>(fx), mem, std::forward<Args>(args)...);
|
2016-06-18 15:32:54 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <F fx>
|
|
|
|
struct invoker {
|
|
|
|
template <typename... Args>
|
|
|
|
decltype(auto) operator()(O& mem, Args&&... args) const {
|
|
|
|
return invoke<fx>(mem, std::forward<Args>(args)...);
|
2016-06-04 09:40:23 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args...)> : public member_function_wrapper<R (O::*)(Args...), R, O, Args...> { };
|
2016-06-04 09:40:23 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args...) const> : public member_function_wrapper<R (O::*)(Args...) const, R, O, Args...> { };
|
2016-06-04 09:40:23 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args...) const volatile> : public member_function_wrapper<R (O::*)(Args...) const volatile, R, O, Args...> { };
|
2016-06-04 09:40:23 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args...)&> : public member_function_wrapper<R (O::*)(Args...)&, R, O, Args...> { };
|
2016-06-04 09:40:23 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args...) const&> : public member_function_wrapper<R (O::*)(Args...) const&, R, O, Args...> { };
|
2016-06-04 09:40:23 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args...) const volatile&> : public member_function_wrapper<R (O::*)(Args...) const volatile&, R, O, Args...> { };
|
2016-06-04 09:40:23 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args..., ...)&> : public member_function_wrapper<R (O::*)(Args..., ...)&, R, O, Args...> { };
|
2016-06-04 09:40:23 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args..., ...) const&> : public member_function_wrapper<R (O::*)(Args..., ...) const&, R, O, Args...> { };
|
2016-06-04 09:40:23 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args..., ...) const volatile&> : public member_function_wrapper<R (O::*)(Args..., ...) const volatile&, R, O, Args...> { };
|
2016-06-04 09:40:23 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args...) &&> : public member_function_wrapper<R (O::*)(Args...)&, R, O, Args...> { };
|
2016-06-04 09:40:23 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args...) const&&> : public member_function_wrapper<R (O::*)(Args...) const&, R, O, Args...> { };
|
2016-06-04 09:40:23 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args...) const volatile&&> : public member_function_wrapper<R (O::*)(Args...) const volatile&, R, O, Args...> { };
|
2016-06-04 09:40:23 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args..., ...) &&> : public member_function_wrapper<R (O::*)(Args..., ...)&, R, O, Args...> { };
|
2016-06-04 09:40:23 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args..., ...) const&&> : public member_function_wrapper<R (O::*)(Args..., ...) const&, R, O, Args...> { };
|
2016-06-04 09:40:23 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args..., ...) const volatile&&> : public member_function_wrapper<R (O::*)(Args..., ...) const volatile&, R, O, Args...> { };
|
2016-06-04 09:40:23 +08:00
|
|
|
|
2020-08-10 05:17:06 +08:00
|
|
|
#if SOL_IS_ON(SOL_USE_NOEXCEPT_FUNCTION_TYPE_I_)
|
|
|
|
// noexcept has become a part of a function's type
|
2017-06-15 01:28:12 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args...) noexcept> : public member_function_wrapper<R (O::*)(Args...) noexcept, R, O, Args...> { };
|
2017-06-15 01:28:12 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args...) const noexcept> : public member_function_wrapper<R (O::*)(Args...) const noexcept, R, O, Args...> { };
|
2017-06-15 01:28:12 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args...) const volatile noexcept> : public member_function_wrapper<R (O::*)(Args...) const volatile noexcept, R, O, Args...> { };
|
2017-06-15 01:28:12 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args...)& noexcept> : public member_function_wrapper<R (O::*)(Args...)& noexcept, R, O, Args...> { };
|
2017-06-15 01:28:12 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args...) const& noexcept> : public member_function_wrapper<R (O::*)(Args...) const& noexcept, R, O, Args...> { };
|
2017-06-15 01:28:12 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args...) const volatile& noexcept> : public member_function_wrapper<R (O::*)(Args...) const volatile& noexcept, R, O, Args...> { };
|
2017-06-15 01:28:12 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args..., ...)& noexcept> : public member_function_wrapper<R (O::*)(Args..., ...)& noexcept, R, O, Args...> { };
|
2017-06-15 01:28:12 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args..., ...) const& noexcept> : public member_function_wrapper<R (O::*)(Args..., ...) const& noexcept, R, O, Args...> { };
|
2017-06-15 01:28:12 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-08-10 05:17:06 +08:00
|
|
|
struct wrapper<R (O::*)(Args..., ...) const volatile& noexcept>
|
2020-12-17 04:25:35 +08:00
|
|
|
: public member_function_wrapper<R (O::*)(Args..., ...) const volatile& noexcept, R, O, Args...> { };
|
2017-06-15 01:28:12 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args...)&& noexcept> : public member_function_wrapper<R (O::*)(Args...)& noexcept, R, O, Args...> { };
|
2017-06-15 01:28:12 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args...) const&& noexcept> : public member_function_wrapper<R (O::*)(Args...) const& noexcept, R, O, Args...> { };
|
2017-06-15 01:28:12 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args...) const volatile&& noexcept> : public member_function_wrapper<R (O::*)(Args...) const volatile& noexcept, R, O, Args...> {
|
|
|
|
};
|
2017-06-15 01:28:12 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args..., ...)&& noexcept> : public member_function_wrapper<R (O::*)(Args..., ...)& noexcept, R, O, Args...> { };
|
2017-06-15 01:28:12 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct wrapper<R (O::*)(Args..., ...) const&& noexcept> : public member_function_wrapper<R (O::*)(Args..., ...) const& noexcept, R, O, Args...> { };
|
2017-06-15 01:28:12 +08:00
|
|
|
|
|
|
|
template <typename R, typename O, typename... Args>
|
2020-08-10 05:17:06 +08:00
|
|
|
struct wrapper<R (O::*)(Args..., ...) const volatile&& noexcept>
|
2020-12-17 04:25:35 +08:00
|
|
|
: public member_function_wrapper<R (O::*)(Args..., ...) const volatile& noexcept, R, O, Args...> { };
|
2017-06-15 01:28:12 +08:00
|
|
|
|
2017-06-17 06:43:40 +08:00
|
|
|
#endif // noexcept is part of a function's type
|
2017-06-15 01:28:12 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
} // namespace sol
|
2016-06-04 09:40:23 +08:00
|
|
|
|
|
|
|
#endif // SOL_WRAPPER_HPP
|