mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
make sure member functions for simple usertypes propogate their desired type.
This commit is contained in:
parent
37420dcdc0
commit
23e3f2c26d
|
@ -20,8 +20,8 @@
|
||||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
// This file was generated with a script.
|
// This file was generated with a script.
|
||||||
// Generated 2017-02-16 04:42:52.309916 UTC
|
// Generated 2017-02-17 10:46:09.695757 UTC
|
||||||
// This header was generated with sol v2.15.8 (revision 4aee6d3)
|
// This header was generated with sol v2.15.8 (revision 37420dc)
|
||||||
// https://github.com/ThePhD/sol2
|
// https://github.com/ThePhD/sol2
|
||||||
|
|
||||||
#ifndef SOL_SINGLE_INCLUDE_HPP
|
#ifndef SOL_SINGLE_INCLUDE_HPP
|
||||||
|
@ -8715,6 +8715,10 @@ namespace sol {
|
||||||
// end of sol/resolve.hpp
|
// end of sol/resolve.hpp
|
||||||
|
|
||||||
namespace sol {
|
namespace sol {
|
||||||
|
namespace function_detail {
|
||||||
|
template<typename T>
|
||||||
|
struct class_indicator {};
|
||||||
|
}
|
||||||
namespace stack {
|
namespace stack {
|
||||||
template<typename... Sigs>
|
template<typename... Sigs>
|
||||||
struct pusher<function_sig<Sigs...>> {
|
struct pusher<function_sig<Sigs...>> {
|
||||||
|
@ -8770,12 +8774,19 @@ namespace sol {
|
||||||
select_convertible(types<Sigs...>(), L, std::forward<Fx>(fx), std::forward<Args>(args)...);
|
select_convertible(types<Sigs...>(), L, std::forward<Fx>(fx), std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Fx, typename T, typename... Args>
|
template <typename Fx, typename T, typename... Args, meta::disable<meta::is_specialization_of<function_detail::class_indicator, meta::unqualified_t<T>>> = meta::enabler>
|
||||||
static void select_member_variable(std::true_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
|
static void select_member_variable(std::true_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
|
||||||
typedef meta::boolean<meta::is_specialization_of<std::reference_wrapper, meta::unqualified_t<T>>::value || std::is_pointer<T>::value> is_reference;
|
typedef meta::boolean<meta::is_specialization_of<std::reference_wrapper, meta::unqualified_t<T>>::value || std::is_pointer<T>::value> is_reference;
|
||||||
select_reference_member_variable(is_reference(), L, std::forward<Fx>(fx), std::forward<T>(obj), std::forward<Args>(args)...);
|
select_reference_member_variable(is_reference(), L, std::forward<Fx>(fx), std::forward<T>(obj), std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Fx, typename C>
|
||||||
|
static void select_member_variable(std::true_type, lua_State* L, Fx&& fx, function_detail::class_indicator<C>) {
|
||||||
|
lua_CFunction freefunc = &function_detail::upvalue_this_member_variable<C, Fx>::call;
|
||||||
|
int upvalues = stack::stack_detail::push_as_upvalues(L, fx);
|
||||||
|
stack::push(L, c_closure(freefunc, upvalues));
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Fx>
|
template <typename Fx>
|
||||||
static void select_member_variable(std::true_type, lua_State* L, Fx&& fx) {
|
static void select_member_variable(std::true_type, lua_State* L, Fx&& fx) {
|
||||||
typedef typename meta::bind_traits<meta::unqualified_t<Fx>>::object_type C;
|
typedef typename meta::bind_traits<meta::unqualified_t<Fx>>::object_type C;
|
||||||
|
@ -8808,12 +8819,19 @@ namespace sol {
|
||||||
select_member_variable(std::is_member_object_pointer<meta::unqualified_t<Fx>>(), L, std::forward<Fx>(fx), std::forward<Args>(args)...);
|
select_member_variable(std::is_member_object_pointer<meta::unqualified_t<Fx>>(), L, std::forward<Fx>(fx), std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Fx, typename T, typename... Args>
|
template <typename Fx, typename T, typename... Args, meta::disable<meta::is_specialization_of<function_detail::class_indicator, meta::unqualified_t<T>>> = meta::enabler>
|
||||||
static void select_member_function(std::true_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
|
static void select_member_function(std::true_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
|
||||||
typedef meta::boolean<meta::is_specialization_of<std::reference_wrapper, meta::unqualified_t<T>>::value || std::is_pointer<T>::value> is_reference;
|
typedef meta::boolean<meta::is_specialization_of<std::reference_wrapper, meta::unqualified_t<T>>::value || std::is_pointer<T>::value> is_reference;
|
||||||
select_reference_member_function(is_reference(), L, std::forward<Fx>(fx), std::forward<T>(obj), std::forward<Args>(args)...);
|
select_reference_member_function(is_reference(), L, std::forward<Fx>(fx), std::forward<T>(obj), std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Fx, typename C>
|
||||||
|
static void select_member_function(std::true_type, lua_State* L, Fx&& fx, function_detail::class_indicator<C>) {
|
||||||
|
lua_CFunction freefunc = &function_detail::upvalue_this_member_function<C, Fx>::call;
|
||||||
|
int upvalues = stack::stack_detail::push_as_upvalues(L, fx);
|
||||||
|
stack::push(L, c_closure(freefunc, upvalues));
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Fx>
|
template <typename Fx>
|
||||||
static void select_member_function(std::true_type, lua_State* L, Fx&& fx) {
|
static void select_member_function(std::true_type, lua_State* L, Fx&& fx) {
|
||||||
typedef typename meta::bind_traits<meta::unqualified_t<Fx>>::object_type C;
|
typedef typename meta::bind_traits<meta::unqualified_t<Fx>>::object_type C;
|
||||||
|
@ -8886,9 +8904,9 @@ namespace sol {
|
||||||
|
|
||||||
template<typename Signature>
|
template<typename Signature>
|
||||||
struct pusher<Signature, std::enable_if_t<std::is_member_pointer<Signature>::value>> {
|
struct pusher<Signature, std::enable_if_t<std::is_member_pointer<Signature>::value>> {
|
||||||
template <typename F>
|
template <typename F, typename... Args>
|
||||||
static int push(lua_State* L, F&& f) {
|
static int push(lua_State* L, F&& f, Args&&... args) {
|
||||||
return pusher<function_sig<>>{}.push(L, std::forward<F>(f));
|
return pusher<function_sig<>>{}.push(L, std::forward<F>(f), std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10807,6 +10825,26 @@ namespace sol {
|
||||||
hint->second = std::move(o);
|
hint->second = std::move(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename N, typename F>
|
||||||
|
void add_member_function(std::true_type, lua_State* L, N&& n, F&& f) {
|
||||||
|
object o = make_object<F>(L, std::forward<F>(f), function_detail::class_indicator<T>());
|
||||||
|
if (std::is_same<meta::unqualified_t<N>, call_construction>::value) {
|
||||||
|
callconstructfunc = std::move(o);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
insert(std::forward<N>(n), std::move(o));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename N, typename F>
|
||||||
|
void add_member_function(std::false_type, lua_State* L, N&& n, F&& f) {
|
||||||
|
object o = make_object<F>(L, std::forward<F>(f));
|
||||||
|
if (std::is_same<meta::unqualified_t<N>, call_construction>::value) {
|
||||||
|
callconstructfunc = std::move(o);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
insert(std::forward<N>(n), std::move(o));
|
||||||
|
}
|
||||||
|
|
||||||
template <typename N, typename F, meta::enable<meta::is_callable<meta::unwrap_unqualified_t<F>>> = meta::enabler>
|
template <typename N, typename F, meta::enable<meta::is_callable<meta::unwrap_unqualified_t<F>>> = meta::enabler>
|
||||||
void add_function(lua_State* L, N&& n, F&& f) {
|
void add_function(lua_State* L, N&& n, F&& f) {
|
||||||
insert(std::forward<N>(n), make_object(L, as_function_reference(std::forward<F>(f))));
|
insert(std::forward<N>(n), make_object(L, as_function_reference(std::forward<F>(f))));
|
||||||
|
@ -10814,12 +10852,7 @@ namespace sol {
|
||||||
|
|
||||||
template <typename N, typename F, meta::disable<meta::is_callable<meta::unwrap_unqualified_t<F>>> = meta::enabler>
|
template <typename N, typename F, meta::disable<meta::is_callable<meta::unwrap_unqualified_t<F>>> = meta::enabler>
|
||||||
void add_function(lua_State* L, N&& n, F&& f) {
|
void add_function(lua_State* L, N&& n, F&& f) {
|
||||||
object o = make_object(L, std::forward<F>(f));
|
add_member_function(std::is_member_pointer<meta::unwrap_unqualified_t<F>>(), L, std::forward<N>(n), std::forward<F>(f));
|
||||||
if (std::is_same<meta::unqualified_t<N>, call_construction>::value) {
|
|
||||||
callconstructfunc = std::move(o);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
insert(std::forward<N>(n), std::move(o));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename N, typename F, meta::disable<is_variable_binding<meta::unqualified_t<F>>> = meta::enabler>
|
template <typename N, typename F, meta::disable<is_variable_binding<meta::unqualified_t<F>>> = meta::enabler>
|
||||||
|
|
|
@ -1,342 +1,360 @@
|
||||||
// The MIT License (MIT)
|
// The MIT License (MIT)
|
||||||
|
|
||||||
// Copyright (c) 2013-2016 Rapptz, ThePhD and contributors
|
// Copyright (c) 2013-2016 Rapptz, ThePhD and contributors
|
||||||
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
// 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
|
// this software and associated documentation files (the "Software"), to deal in
|
||||||
// the Software without restriction, including without limitation the rights to
|
// the Software without restriction, including without limitation the rights to
|
||||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
// 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,
|
// the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
// subject to the following conditions:
|
// subject to the following conditions:
|
||||||
|
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
// 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
|
// 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
|
// 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.
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
#ifndef SOL_FUNCTION_TYPES_HPP
|
#ifndef SOL_FUNCTION_TYPES_HPP
|
||||||
#define SOL_FUNCTION_TYPES_HPP
|
#define SOL_FUNCTION_TYPES_HPP
|
||||||
|
|
||||||
#include "function_types_core.hpp"
|
#include "function_types_core.hpp"
|
||||||
#include "function_types_templated.hpp"
|
#include "function_types_templated.hpp"
|
||||||
#include "function_types_stateless.hpp"
|
#include "function_types_stateless.hpp"
|
||||||
#include "function_types_stateful.hpp"
|
#include "function_types_stateful.hpp"
|
||||||
#include "function_types_overloaded.hpp"
|
#include "function_types_overloaded.hpp"
|
||||||
#include "resolve.hpp"
|
#include "resolve.hpp"
|
||||||
#include "call.hpp"
|
#include "call.hpp"
|
||||||
|
|
||||||
namespace sol {
|
namespace sol {
|
||||||
namespace stack {
|
namespace function_detail {
|
||||||
template<typename... Sigs>
|
template<typename T>
|
||||||
struct pusher<function_sig<Sigs...>> {
|
struct class_indicator {};
|
||||||
template <typename... Sig, typename Fx, typename... Args>
|
}
|
||||||
static void select_convertible(std::false_type, types<Sig...>, lua_State* L, Fx&& fx, Args&&... args) {
|
namespace stack {
|
||||||
typedef std::remove_pointer_t<std::decay_t<Fx>> clean_fx;
|
template<typename... Sigs>
|
||||||
typedef function_detail::functor_function<clean_fx> F;
|
struct pusher<function_sig<Sigs...>> {
|
||||||
set_fx<F>(L, std::forward<Fx>(fx), std::forward<Args>(args)...);
|
template <typename... Sig, typename Fx, typename... Args>
|
||||||
}
|
static void select_convertible(std::false_type, types<Sig...>, lua_State* L, Fx&& fx, Args&&... args) {
|
||||||
|
typedef std::remove_pointer_t<std::decay_t<Fx>> clean_fx;
|
||||||
template <typename R, typename... A, typename Fx, typename... Args>
|
typedef function_detail::functor_function<clean_fx> F;
|
||||||
static void select_convertible(std::true_type, types<R(A...)>, lua_State* L, Fx&& fx, Args&&... args) {
|
set_fx<F>(L, std::forward<Fx>(fx), std::forward<Args>(args)...);
|
||||||
using fx_ptr_t = R(*)(A...);
|
}
|
||||||
fx_ptr_t fxptr = detail::unwrap(std::forward<Fx>(fx));
|
|
||||||
select_function(std::true_type(), L, fxptr, std::forward<Args>(args)...);
|
template <typename R, typename... A, typename Fx, typename... Args>
|
||||||
}
|
static void select_convertible(std::true_type, types<R(A...)>, lua_State* L, Fx&& fx, Args&&... args) {
|
||||||
|
using fx_ptr_t = R(*)(A...);
|
||||||
template <typename R, typename... A, typename Fx, typename... Args>
|
fx_ptr_t fxptr = detail::unwrap(std::forward<Fx>(fx));
|
||||||
static void select_convertible(types<R(A...)> t, lua_State* L, Fx&& fx, Args&&... args) {
|
select_function(std::true_type(), L, fxptr, std::forward<Args>(args)...);
|
||||||
typedef std::decay_t<meta::unwrap_unqualified_t<Fx>> raw_fx_t;
|
}
|
||||||
typedef R(*fx_ptr_t)(A...);
|
|
||||||
typedef std::is_convertible<raw_fx_t, fx_ptr_t> is_convertible;
|
template <typename R, typename... A, typename Fx, typename... Args>
|
||||||
select_convertible(is_convertible(), t, L, std::forward<Fx>(fx), std::forward<Args>(args)...);
|
static void select_convertible(types<R(A...)> t, lua_State* L, Fx&& fx, Args&&... args) {
|
||||||
}
|
typedef std::decay_t<meta::unwrap_unqualified_t<Fx>> raw_fx_t;
|
||||||
|
typedef R(*fx_ptr_t)(A...);
|
||||||
template <typename Fx, typename... Args>
|
typedef std::is_convertible<raw_fx_t, fx_ptr_t> is_convertible;
|
||||||
static void select_convertible(types<>, lua_State* L, Fx&& fx, Args&&... args) {
|
select_convertible(is_convertible(), t, L, std::forward<Fx>(fx), std::forward<Args>(args)...);
|
||||||
typedef meta::function_signature_t<meta::unwrap_unqualified_t<Fx>> Sig;
|
}
|
||||||
select_convertible(types<Sig>(), L, std::forward<Fx>(fx), std::forward<Args>(args)...);
|
|
||||||
}
|
template <typename Fx, typename... Args>
|
||||||
|
static void select_convertible(types<>, lua_State* L, Fx&& fx, Args&&... args) {
|
||||||
template <typename Fx, typename T, typename... Args>
|
typedef meta::function_signature_t<meta::unwrap_unqualified_t<Fx>> Sig;
|
||||||
static void select_reference_member_variable(std::false_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
|
select_convertible(types<Sig>(), L, std::forward<Fx>(fx), std::forward<Args>(args)...);
|
||||||
typedef std::remove_pointer_t<std::decay_t<Fx>> clean_fx;
|
}
|
||||||
typedef function_detail::member_variable<meta::unwrap_unqualified_t<T>, clean_fx> F;
|
|
||||||
set_fx<F>(L, std::forward<Fx>(fx), std::forward<T>(obj), std::forward<Args>(args)...);
|
template <typename Fx, typename T, typename... Args>
|
||||||
}
|
static void select_reference_member_variable(std::false_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
|
||||||
|
typedef std::remove_pointer_t<std::decay_t<Fx>> clean_fx;
|
||||||
template <typename Fx, typename T, typename... Args>
|
typedef function_detail::member_variable<meta::unwrap_unqualified_t<T>, clean_fx> F;
|
||||||
static void select_reference_member_variable(std::true_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
|
set_fx<F>(L, std::forward<Fx>(fx), std::forward<T>(obj), std::forward<Args>(args)...);
|
||||||
typedef std::decay_t<Fx> dFx;
|
}
|
||||||
dFx memfxptr(std::forward<Fx>(fx));
|
|
||||||
auto userptr = detail::ptr(std::forward<T>(obj), std::forward<Args>(args)...);
|
template <typename Fx, typename T, typename... Args>
|
||||||
lua_CFunction freefunc = &function_detail::upvalue_member_variable<std::decay_t<decltype(*userptr)>, meta::unqualified_t<Fx>>::call;
|
static void select_reference_member_variable(std::true_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
|
||||||
|
typedef std::decay_t<Fx> dFx;
|
||||||
int upvalues = stack::stack_detail::push_as_upvalues(L, memfxptr);
|
dFx memfxptr(std::forward<Fx>(fx));
|
||||||
upvalues += stack::push(L, lightuserdata_value(static_cast<void*>(userptr)));
|
auto userptr = detail::ptr(std::forward<T>(obj), std::forward<Args>(args)...);
|
||||||
stack::push(L, c_closure(freefunc, upvalues));
|
lua_CFunction freefunc = &function_detail::upvalue_member_variable<std::decay_t<decltype(*userptr)>, meta::unqualified_t<Fx>>::call;
|
||||||
}
|
|
||||||
|
int upvalues = stack::stack_detail::push_as_upvalues(L, memfxptr);
|
||||||
template <typename Fx, typename... Args>
|
upvalues += stack::push(L, lightuserdata_value(static_cast<void*>(userptr)));
|
||||||
static void select_member_variable(std::false_type, lua_State* L, Fx&& fx, Args&&... args) {
|
stack::push(L, c_closure(freefunc, upvalues));
|
||||||
select_convertible(types<Sigs...>(), L, std::forward<Fx>(fx), std::forward<Args>(args)...);
|
}
|
||||||
}
|
|
||||||
|
template <typename Fx, typename... Args>
|
||||||
template <typename Fx, typename T, typename... Args>
|
static void select_member_variable(std::false_type, lua_State* L, Fx&& fx, Args&&... args) {
|
||||||
static void select_member_variable(std::true_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
|
select_convertible(types<Sigs...>(), L, std::forward<Fx>(fx), std::forward<Args>(args)...);
|
||||||
typedef meta::boolean<meta::is_specialization_of<std::reference_wrapper, meta::unqualified_t<T>>::value || std::is_pointer<T>::value> is_reference;
|
}
|
||||||
select_reference_member_variable(is_reference(), L, std::forward<Fx>(fx), std::forward<T>(obj), std::forward<Args>(args)...);
|
|
||||||
}
|
template <typename Fx, typename T, typename... Args, meta::disable<meta::is_specialization_of<function_detail::class_indicator, meta::unqualified_t<T>>> = meta::enabler>
|
||||||
|
static void select_member_variable(std::true_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
|
||||||
template <typename Fx>
|
typedef meta::boolean<meta::is_specialization_of<std::reference_wrapper, meta::unqualified_t<T>>::value || std::is_pointer<T>::value> is_reference;
|
||||||
static void select_member_variable(std::true_type, lua_State* L, Fx&& fx) {
|
select_reference_member_variable(is_reference(), L, std::forward<Fx>(fx), std::forward<T>(obj), std::forward<Args>(args)...);
|
||||||
typedef typename meta::bind_traits<meta::unqualified_t<Fx>>::object_type C;
|
}
|
||||||
lua_CFunction freefunc = &function_detail::upvalue_this_member_variable<C, Fx>::call;
|
|
||||||
int upvalues = stack::stack_detail::push_as_upvalues(L, fx);
|
template <typename Fx, typename C>
|
||||||
stack::push(L, c_closure(freefunc, upvalues));
|
static void select_member_variable(std::true_type, lua_State* L, Fx&& fx, function_detail::class_indicator<C>) {
|
||||||
}
|
lua_CFunction freefunc = &function_detail::upvalue_this_member_variable<C, Fx>::call;
|
||||||
|
int upvalues = stack::stack_detail::push_as_upvalues(L, fx);
|
||||||
template <typename Fx, typename T, typename... Args>
|
stack::push(L, c_closure(freefunc, upvalues));
|
||||||
static void select_reference_member_function(std::false_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
|
}
|
||||||
typedef std::decay_t<Fx> clean_fx;
|
|
||||||
typedef function_detail::member_function<meta::unwrap_unqualified_t<T>, clean_fx> F;
|
template <typename Fx>
|
||||||
set_fx<F>(L, std::forward<Fx>(fx), std::forward<T>(obj), std::forward<Args>(args)...);
|
static void select_member_variable(std::true_type, lua_State* L, Fx&& fx) {
|
||||||
}
|
typedef typename meta::bind_traits<meta::unqualified_t<Fx>>::object_type C;
|
||||||
|
lua_CFunction freefunc = &function_detail::upvalue_this_member_variable<C, Fx>::call;
|
||||||
template <typename Fx, typename T, typename... Args>
|
int upvalues = stack::stack_detail::push_as_upvalues(L, fx);
|
||||||
static void select_reference_member_function(std::true_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
|
stack::push(L, c_closure(freefunc, upvalues));
|
||||||
typedef std::decay_t<Fx> dFx;
|
}
|
||||||
dFx memfxptr(std::forward<Fx>(fx));
|
|
||||||
auto userptr = detail::ptr(std::forward<T>(obj), std::forward<Args>(args)...);
|
template <typename Fx, typename T, typename... Args>
|
||||||
lua_CFunction freefunc = &function_detail::upvalue_member_function<std::decay_t<decltype(*userptr)>, meta::unqualified_t<Fx>>::call;
|
static void select_reference_member_function(std::false_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
|
||||||
|
typedef std::decay_t<Fx> clean_fx;
|
||||||
int upvalues = stack::stack_detail::push_as_upvalues(L, memfxptr);
|
typedef function_detail::member_function<meta::unwrap_unqualified_t<T>, clean_fx> F;
|
||||||
upvalues += stack::push(L, lightuserdata_value(static_cast<void*>(userptr)));
|
set_fx<F>(L, std::forward<Fx>(fx), std::forward<T>(obj), std::forward<Args>(args)...);
|
||||||
stack::push(L, c_closure(freefunc, upvalues));
|
}
|
||||||
}
|
|
||||||
|
template <typename Fx, typename T, typename... Args>
|
||||||
template <typename Fx, typename... Args>
|
static void select_reference_member_function(std::true_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
|
||||||
static void select_member_function(std::false_type, lua_State* L, Fx&& fx, Args&&... args) {
|
typedef std::decay_t<Fx> dFx;
|
||||||
select_member_variable(std::is_member_object_pointer<meta::unqualified_t<Fx>>(), L, std::forward<Fx>(fx), std::forward<Args>(args)...);
|
dFx memfxptr(std::forward<Fx>(fx));
|
||||||
}
|
auto userptr = detail::ptr(std::forward<T>(obj), std::forward<Args>(args)...);
|
||||||
|
lua_CFunction freefunc = &function_detail::upvalue_member_function<std::decay_t<decltype(*userptr)>, meta::unqualified_t<Fx>>::call;
|
||||||
template <typename Fx, typename T, typename... Args>
|
|
||||||
static void select_member_function(std::true_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
|
int upvalues = stack::stack_detail::push_as_upvalues(L, memfxptr);
|
||||||
typedef meta::boolean<meta::is_specialization_of<std::reference_wrapper, meta::unqualified_t<T>>::value || std::is_pointer<T>::value> is_reference;
|
upvalues += stack::push(L, lightuserdata_value(static_cast<void*>(userptr)));
|
||||||
select_reference_member_function(is_reference(), L, std::forward<Fx>(fx), std::forward<T>(obj), std::forward<Args>(args)...);
|
stack::push(L, c_closure(freefunc, upvalues));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Fx>
|
template <typename Fx, typename... Args>
|
||||||
static void select_member_function(std::true_type, lua_State* L, Fx&& fx) {
|
static void select_member_function(std::false_type, lua_State* L, Fx&& fx, Args&&... args) {
|
||||||
typedef typename meta::bind_traits<meta::unqualified_t<Fx>>::object_type C;
|
select_member_variable(std::is_member_object_pointer<meta::unqualified_t<Fx>>(), L, std::forward<Fx>(fx), std::forward<Args>(args)...);
|
||||||
lua_CFunction freefunc = &function_detail::upvalue_this_member_function<C, Fx>::call;
|
}
|
||||||
int upvalues = stack::stack_detail::push_as_upvalues(L, fx);
|
|
||||||
stack::push(L, c_closure(freefunc, upvalues));
|
template <typename Fx, typename T, typename... Args, meta::disable<meta::is_specialization_of<function_detail::class_indicator, meta::unqualified_t<T>>> = meta::enabler>
|
||||||
}
|
static void select_member_function(std::true_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
|
||||||
|
typedef meta::boolean<meta::is_specialization_of<std::reference_wrapper, meta::unqualified_t<T>>::value || std::is_pointer<T>::value> is_reference;
|
||||||
template <typename Fx, typename... Args>
|
select_reference_member_function(is_reference(), L, std::forward<Fx>(fx), std::forward<T>(obj), std::forward<Args>(args)...);
|
||||||
static void select_function(std::false_type, lua_State* L, Fx&& fx, Args&&... args) {
|
}
|
||||||
select_member_function(std::is_member_function_pointer<meta::unqualified_t<Fx>>(), L, std::forward<Fx>(fx), std::forward<Args>(args)...);
|
|
||||||
}
|
template <typename Fx, typename C>
|
||||||
|
static void select_member_function(std::true_type, lua_State* L, Fx&& fx, function_detail::class_indicator<C>) {
|
||||||
template <typename Fx, typename... Args>
|
lua_CFunction freefunc = &function_detail::upvalue_this_member_function<C, Fx>::call;
|
||||||
static void select_function(std::true_type, lua_State* L, Fx&& fx, Args&&... args) {
|
int upvalues = stack::stack_detail::push_as_upvalues(L, fx);
|
||||||
std::decay_t<Fx> target(std::forward<Fx>(fx), std::forward<Args>(args)...);
|
stack::push(L, c_closure(freefunc, upvalues));
|
||||||
lua_CFunction freefunc = &function_detail::upvalue_free_function<Fx>::call;
|
}
|
||||||
|
|
||||||
int upvalues = stack::stack_detail::push_as_upvalues(L, target);
|
template <typename Fx>
|
||||||
stack::push(L, c_closure(freefunc, upvalues));
|
static void select_member_function(std::true_type, lua_State* L, Fx&& fx) {
|
||||||
}
|
typedef typename meta::bind_traits<meta::unqualified_t<Fx>>::object_type C;
|
||||||
|
lua_CFunction freefunc = &function_detail::upvalue_this_member_function<C, Fx>::call;
|
||||||
static void select_function(std::true_type, lua_State* L, lua_CFunction f) {
|
int upvalues = stack::stack_detail::push_as_upvalues(L, fx);
|
||||||
stack::push(L, f);
|
stack::push(L, c_closure(freefunc, upvalues));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Fx, typename... Args>
|
template <typename Fx, typename... Args>
|
||||||
static void select(lua_State* L, Fx&& fx, Args&&... args) {
|
static void select_function(std::false_type, lua_State* L, Fx&& fx, Args&&... args) {
|
||||||
select_function(std::is_function<meta::unqualified_t<Fx>>(), L, std::forward<Fx>(fx), std::forward<Args>(args)...);
|
select_member_function(std::is_member_function_pointer<meta::unqualified_t<Fx>>(), L, std::forward<Fx>(fx), std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Fx, typename... Args>
|
template <typename Fx, typename... Args>
|
||||||
static void set_fx(lua_State* L, Args&&... args) {
|
static void select_function(std::true_type, lua_State* L, Fx&& fx, Args&&... args) {
|
||||||
lua_CFunction freefunc = function_detail::call<meta::unqualified_t<Fx>>;
|
std::decay_t<Fx> target(std::forward<Fx>(fx), std::forward<Args>(args)...);
|
||||||
|
lua_CFunction freefunc = &function_detail::upvalue_free_function<Fx>::call;
|
||||||
stack::push<user<Fx>>(L, std::forward<Args>(args)...);
|
|
||||||
stack::push(L, c_closure(freefunc, 1));
|
int upvalues = stack::stack_detail::push_as_upvalues(L, target);
|
||||||
}
|
stack::push(L, c_closure(freefunc, upvalues));
|
||||||
|
}
|
||||||
template<typename... Args>
|
|
||||||
static int push(lua_State* L, Args&&... args) {
|
static void select_function(std::true_type, lua_State* L, lua_CFunction f) {
|
||||||
// Set will always place one thing (function) on the stack
|
stack::push(L, f);
|
||||||
select(L, std::forward<Args>(args)...);
|
}
|
||||||
return 1;
|
|
||||||
}
|
template <typename Fx, typename... Args>
|
||||||
};
|
static void select(lua_State* L, Fx&& fx, Args&&... args) {
|
||||||
|
select_function(std::is_function<meta::unqualified_t<Fx>>(), L, std::forward<Fx>(fx), std::forward<Args>(args)...);
|
||||||
template<typename T, typename... Args>
|
}
|
||||||
struct pusher<function_arguments<T, Args...>> {
|
|
||||||
template <std::size_t... I, typename FP>
|
template <typename Fx, typename... Args>
|
||||||
static int push_func(std::index_sequence<I...>, lua_State* L, FP&& fp) {
|
static void set_fx(lua_State* L, Args&&... args) {
|
||||||
return stack::push<T>(L, detail::forward_get<I>(fp.arguments)...);
|
lua_CFunction freefunc = function_detail::call<meta::unqualified_t<Fx>>;
|
||||||
}
|
|
||||||
|
stack::push<user<Fx>>(L, std::forward<Args>(args)...);
|
||||||
static int push(lua_State* L, const function_arguments<T, Args...>& fp) {
|
stack::push(L, c_closure(freefunc, 1));
|
||||||
return push_func(std::make_index_sequence<sizeof...(Args)>(), L, fp);
|
}
|
||||||
}
|
|
||||||
|
template<typename... Args>
|
||||||
static int push(lua_State* L, function_arguments<T, Args...>&& fp) {
|
static int push(lua_State* L, Args&&... args) {
|
||||||
return push_func(std::make_index_sequence<sizeof...(Args)>(), L, std::move(fp));
|
// Set will always place one thing (function) on the stack
|
||||||
}
|
select(L, std::forward<Args>(args)...);
|
||||||
};
|
return 1;
|
||||||
|
}
|
||||||
template<typename Signature>
|
};
|
||||||
struct pusher<std::function<Signature>> {
|
|
||||||
static int push(lua_State* L, std::function<Signature> fx) {
|
template<typename T, typename... Args>
|
||||||
return pusher<function_sig<Signature>>{}.push(L, std::move(fx));
|
struct pusher<function_arguments<T, Args...>> {
|
||||||
}
|
template <std::size_t... I, typename FP>
|
||||||
};
|
static int push_func(std::index_sequence<I...>, lua_State* L, FP&& fp) {
|
||||||
|
return stack::push<T>(L, detail::forward_get<I>(fp.arguments)...);
|
||||||
template<typename Signature>
|
}
|
||||||
struct pusher<Signature, std::enable_if_t<std::is_member_pointer<Signature>::value>> {
|
|
||||||
template <typename F>
|
static int push(lua_State* L, const function_arguments<T, Args...>& fp) {
|
||||||
static int push(lua_State* L, F&& f) {
|
return push_func(std::make_index_sequence<sizeof...(Args)>(), L, fp);
|
||||||
return pusher<function_sig<>>{}.push(L, std::forward<F>(f));
|
}
|
||||||
}
|
|
||||||
};
|
static int push(lua_State* L, function_arguments<T, Args...>&& fp) {
|
||||||
|
return push_func(std::make_index_sequence<sizeof...(Args)>(), L, std::move(fp));
|
||||||
template<typename Signature>
|
}
|
||||||
struct pusher<Signature, std::enable_if_t<meta::all<std::is_function<Signature>, meta::neg<std::is_same<Signature, lua_CFunction>>, meta::neg<std::is_same<Signature, std::remove_pointer_t<lua_CFunction>>>>::value>> {
|
};
|
||||||
template <typename F>
|
|
||||||
static int push(lua_State* L, F&& f) {
|
template<typename Signature>
|
||||||
return pusher<function_sig<>>{}.push(L, std::forward<F>(f));
|
struct pusher<std::function<Signature>> {
|
||||||
}
|
static int push(lua_State* L, std::function<Signature> fx) {
|
||||||
};
|
return pusher<function_sig<Signature>>{}.push(L, std::move(fx));
|
||||||
|
}
|
||||||
template<typename... Functions>
|
};
|
||||||
struct pusher<overload_set<Functions...>> {
|
|
||||||
static int push(lua_State* L, overload_set<Functions...>&& set) {
|
template<typename Signature>
|
||||||
typedef function_detail::overloaded_function<Functions...> F;
|
struct pusher<Signature, std::enable_if_t<std::is_member_pointer<Signature>::value>> {
|
||||||
pusher<function_sig<>>{}.set_fx<F>(L, std::move(set.functions));
|
template <typename F, typename... Args>
|
||||||
return 1;
|
static int push(lua_State* L, F&& f, Args&&... args) {
|
||||||
}
|
return pusher<function_sig<>>{}.push(L, std::forward<F>(f), std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
static int push(lua_State* L, const overload_set<Functions...>& set) {
|
};
|
||||||
typedef function_detail::overloaded_function<Functions...> F;
|
|
||||||
pusher<function_sig<>>{}.set_fx<F>(L, set.functions);
|
template<typename Signature>
|
||||||
return 1;
|
struct pusher<Signature, std::enable_if_t<meta::all<std::is_function<Signature>, meta::neg<std::is_same<Signature, lua_CFunction>>, meta::neg<std::is_same<Signature, std::remove_pointer_t<lua_CFunction>>>>::value>> {
|
||||||
}
|
template <typename F>
|
||||||
};
|
static int push(lua_State* L, F&& f) {
|
||||||
|
return pusher<function_sig<>>{}.push(L, std::forward<F>(f));
|
||||||
template <typename T>
|
}
|
||||||
struct pusher<protect_t<T>> {
|
};
|
||||||
static int push(lua_State* L, protect_t<T>&& pw) {
|
|
||||||
lua_CFunction cf = call_detail::call_user<void, false, false, protect_t<T>>;
|
template<typename... Functions>
|
||||||
int closures = stack::push<user<protect_t<T>>>(L, std::move(pw.value));
|
struct pusher<overload_set<Functions...>> {
|
||||||
return stack::push(L, c_closure(cf, closures));
|
static int push(lua_State* L, overload_set<Functions...>&& set) {
|
||||||
}
|
typedef function_detail::overloaded_function<Functions...> F;
|
||||||
|
pusher<function_sig<>>{}.set_fx<F>(L, std::move(set.functions));
|
||||||
static int push(lua_State* L, const protect_t<T>& pw) {
|
return 1;
|
||||||
lua_CFunction cf = call_detail::call_user<void, false, false, protect_t<T>>;
|
}
|
||||||
int closures = stack::push<user<protect_t<T>>>(L, pw.value);
|
|
||||||
return stack::push(L, c_closure(cf, closures));
|
static int push(lua_State* L, const overload_set<Functions...>& set) {
|
||||||
}
|
typedef function_detail::overloaded_function<Functions...> F;
|
||||||
};
|
pusher<function_sig<>>{}.set_fx<F>(L, set.functions);
|
||||||
|
return 1;
|
||||||
template <typename F, typename G>
|
}
|
||||||
struct pusher<property_wrapper<F, G>, std::enable_if_t<!std::is_void<F>::value && !std::is_void<G>::value>> {
|
};
|
||||||
static int push(lua_State* L, property_wrapper<F, G>&& pw) {
|
|
||||||
return stack::push(L, sol::overload(std::move(pw.read), std::move(pw.write)));
|
template <typename T>
|
||||||
}
|
struct pusher<protect_t<T>> {
|
||||||
static int push(lua_State* L, const property_wrapper<F, G>& pw) {
|
static int push(lua_State* L, protect_t<T>&& pw) {
|
||||||
return stack::push(L, sol::overload(pw.read, pw.write));
|
lua_CFunction cf = call_detail::call_user<void, false, false, protect_t<T>>;
|
||||||
}
|
int closures = stack::push<user<protect_t<T>>>(L, std::move(pw.value));
|
||||||
};
|
return stack::push(L, c_closure(cf, closures));
|
||||||
|
}
|
||||||
template <typename F>
|
|
||||||
struct pusher<property_wrapper<F, void>> {
|
static int push(lua_State* L, const protect_t<T>& pw) {
|
||||||
static int push(lua_State* L, property_wrapper<F, void>&& pw) {
|
lua_CFunction cf = call_detail::call_user<void, false, false, protect_t<T>>;
|
||||||
return stack::push(L, std::move(pw.read));
|
int closures = stack::push<user<protect_t<T>>>(L, pw.value);
|
||||||
}
|
return stack::push(L, c_closure(cf, closures));
|
||||||
static int push(lua_State* L, const property_wrapper<F, void>& pw) {
|
}
|
||||||
return stack::push(L, pw.read);
|
};
|
||||||
}
|
|
||||||
};
|
template <typename F, typename G>
|
||||||
|
struct pusher<property_wrapper<F, G>, std::enable_if_t<!std::is_void<F>::value && !std::is_void<G>::value>> {
|
||||||
template <typename F>
|
static int push(lua_State* L, property_wrapper<F, G>&& pw) {
|
||||||
struct pusher<property_wrapper<void, F>> {
|
return stack::push(L, sol::overload(std::move(pw.read), std::move(pw.write)));
|
||||||
static int push(lua_State* L, property_wrapper<void, F>&& pw) {
|
}
|
||||||
return stack::push(L, std::move(pw.write));
|
static int push(lua_State* L, const property_wrapper<F, G>& pw) {
|
||||||
}
|
return stack::push(L, sol::overload(pw.read, pw.write));
|
||||||
static int push(lua_State* L, const property_wrapper<void, F>& pw) {
|
}
|
||||||
return stack::push(L, pw.write);
|
};
|
||||||
}
|
|
||||||
};
|
template <typename F>
|
||||||
|
struct pusher<property_wrapper<F, void>> {
|
||||||
template <typename T>
|
static int push(lua_State* L, property_wrapper<F, void>&& pw) {
|
||||||
struct pusher<var_wrapper<T>> {
|
return stack::push(L, std::move(pw.read));
|
||||||
static int push(lua_State* L, var_wrapper<T>&& vw) {
|
}
|
||||||
return stack::push(L, std::move(vw.value));
|
static int push(lua_State* L, const property_wrapper<F, void>& pw) {
|
||||||
}
|
return stack::push(L, pw.read);
|
||||||
static int push(lua_State* L, const var_wrapper<T>& vw) {
|
}
|
||||||
return stack::push(L, vw.value);
|
};
|
||||||
}
|
|
||||||
};
|
template <typename F>
|
||||||
|
struct pusher<property_wrapper<void, F>> {
|
||||||
template <typename... Functions>
|
static int push(lua_State* L, property_wrapper<void, F>&& pw) {
|
||||||
struct pusher<factory_wrapper<Functions...>> {
|
return stack::push(L, std::move(pw.write));
|
||||||
static int push(lua_State* L, const factory_wrapper<Functions...>& fw) {
|
}
|
||||||
typedef function_detail::overloaded_function<Functions...> F;
|
static int push(lua_State* L, const property_wrapper<void, F>& pw) {
|
||||||
pusher<function_sig<>>{}.set_fx<F>(L, fw.functions);
|
return stack::push(L, pw.write);
|
||||||
return 1;
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
static int push(lua_State* L, factory_wrapper<Functions...>&& fw) {
|
template <typename T>
|
||||||
typedef function_detail::overloaded_function<Functions...> F;
|
struct pusher<var_wrapper<T>> {
|
||||||
pusher<function_sig<>>{}.set_fx<F>(L, std::move(fw.functions));
|
static int push(lua_State* L, var_wrapper<T>&& vw) {
|
||||||
return 1;
|
return stack::push(L, std::move(vw.value));
|
||||||
}
|
}
|
||||||
};
|
static int push(lua_State* L, const var_wrapper<T>& vw) {
|
||||||
|
return stack::push(L, vw.value);
|
||||||
template <typename T, typename... Lists>
|
}
|
||||||
struct pusher<detail::tagged<T, constructor_list<Lists...>>> {
|
};
|
||||||
static int push(lua_State* L, detail::tagged<T, constructor_list<Lists...>>) {
|
|
||||||
lua_CFunction cf = call_detail::construct<T, Lists...>;
|
template <typename... Functions>
|
||||||
return stack::push(L, cf);
|
struct pusher<factory_wrapper<Functions...>> {
|
||||||
}
|
static int push(lua_State* L, const factory_wrapper<Functions...>& fw) {
|
||||||
};
|
typedef function_detail::overloaded_function<Functions...> F;
|
||||||
|
pusher<function_sig<>>{}.set_fx<F>(L, fw.functions);
|
||||||
template <typename T, typename... Fxs>
|
return 1;
|
||||||
struct pusher<detail::tagged<T, constructor_wrapper<Fxs...>>> {
|
}
|
||||||
template <typename C>
|
|
||||||
static int push(lua_State* L, C&& c) {
|
static int push(lua_State* L, factory_wrapper<Functions...>&& fw) {
|
||||||
lua_CFunction cf = call_detail::call_user<T, false, false, constructor_wrapper<Fxs...>>;
|
typedef function_detail::overloaded_function<Functions...> F;
|
||||||
int closures = stack::push<user<constructor_wrapper<Fxs...>>>(L, std::forward<C>(c));
|
pusher<function_sig<>>{}.set_fx<F>(L, std::move(fw.functions));
|
||||||
return stack::push(L, c_closure(cf, closures));
|
return 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename... Lists>
|
||||||
struct pusher<detail::tagged<T, destructor_wrapper<void>>> {
|
struct pusher<detail::tagged<T, constructor_list<Lists...>>> {
|
||||||
static int push(lua_State* L, destructor_wrapper<void>) {
|
static int push(lua_State* L, detail::tagged<T, constructor_list<Lists...>>) {
|
||||||
lua_CFunction cf = detail::usertype_alloc_destroy<T>;
|
lua_CFunction cf = call_detail::construct<T, Lists...>;
|
||||||
return stack::push(L, cf);
|
return stack::push(L, cf);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, typename Fx>
|
template <typename T, typename... Fxs>
|
||||||
struct pusher<detail::tagged<T, destructor_wrapper<Fx>>> {
|
struct pusher<detail::tagged<T, constructor_wrapper<Fxs...>>> {
|
||||||
static int push(lua_State* L, destructor_wrapper<Fx> c) {
|
template <typename C>
|
||||||
lua_CFunction cf = call_detail::call_user<T, false, false, destructor_wrapper<Fx>>;
|
static int push(lua_State* L, C&& c) {
|
||||||
int closures = stack::push<user<T>>(L, std::move(c));
|
lua_CFunction cf = call_detail::call_user<T, false, false, constructor_wrapper<Fxs...>>;
|
||||||
return stack::push(L, c_closure(cf, closures));
|
int closures = stack::push<user<constructor_wrapper<Fxs...>>>(L, std::forward<C>(c));
|
||||||
}
|
return stack::push(L, c_closure(cf, closures));
|
||||||
};
|
}
|
||||||
|
};
|
||||||
} // stack
|
|
||||||
} // sol
|
template <typename T>
|
||||||
|
struct pusher<detail::tagged<T, destructor_wrapper<void>>> {
|
||||||
#endif // SOL_FUNCTION_TYPES_HPP
|
static int push(lua_State* L, destructor_wrapper<void>) {
|
||||||
|
lua_CFunction cf = detail::usertype_alloc_destroy<T>;
|
||||||
|
return stack::push(L, cf);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T, typename Fx>
|
||||||
|
struct pusher<detail::tagged<T, destructor_wrapper<Fx>>> {
|
||||||
|
static int push(lua_State* L, destructor_wrapper<Fx> c) {
|
||||||
|
lua_CFunction cf = call_detail::call_user<T, false, false, destructor_wrapper<Fx>>;
|
||||||
|
int closures = stack::push<user<T>>(L, std::move(c));
|
||||||
|
return stack::push(L, c_closure(cf, closures));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // stack
|
||||||
|
} // sol
|
||||||
|
|
||||||
|
#endif // SOL_FUNCTION_TYPES_HPP
|
||||||
|
|
|
@ -208,6 +208,26 @@ namespace sol {
|
||||||
hint->second = std::move(o);
|
hint->second = std::move(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename N, typename F>
|
||||||
|
void add_member_function(std::true_type, lua_State* L, N&& n, F&& f) {
|
||||||
|
object o = make_object<F>(L, std::forward<F>(f), function_detail::class_indicator<T>());
|
||||||
|
if (std::is_same<meta::unqualified_t<N>, call_construction>::value) {
|
||||||
|
callconstructfunc = std::move(o);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
insert(std::forward<N>(n), std::move(o));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename N, typename F>
|
||||||
|
void add_member_function(std::false_type, lua_State* L, N&& n, F&& f) {
|
||||||
|
object o = make_object<F>(L, std::forward<F>(f));
|
||||||
|
if (std::is_same<meta::unqualified_t<N>, call_construction>::value) {
|
||||||
|
callconstructfunc = std::move(o);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
insert(std::forward<N>(n), std::move(o));
|
||||||
|
}
|
||||||
|
|
||||||
template <typename N, typename F, meta::enable<meta::is_callable<meta::unwrap_unqualified_t<F>>> = meta::enabler>
|
template <typename N, typename F, meta::enable<meta::is_callable<meta::unwrap_unqualified_t<F>>> = meta::enabler>
|
||||||
void add_function(lua_State* L, N&& n, F&& f) {
|
void add_function(lua_State* L, N&& n, F&& f) {
|
||||||
insert(std::forward<N>(n), make_object(L, as_function_reference(std::forward<F>(f))));
|
insert(std::forward<N>(n), make_object(L, as_function_reference(std::forward<F>(f))));
|
||||||
|
@ -215,12 +235,7 @@ namespace sol {
|
||||||
|
|
||||||
template <typename N, typename F, meta::disable<meta::is_callable<meta::unwrap_unqualified_t<F>>> = meta::enabler>
|
template <typename N, typename F, meta::disable<meta::is_callable<meta::unwrap_unqualified_t<F>>> = meta::enabler>
|
||||||
void add_function(lua_State* L, N&& n, F&& f) {
|
void add_function(lua_State* L, N&& n, F&& f) {
|
||||||
object o = make_object(L, std::forward<F>(f));
|
add_member_function(std::is_member_pointer<meta::unwrap_unqualified_t<F>>(), L, std::forward<N>(n), std::forward<F>(f));
|
||||||
if (std::is_same<meta::unqualified_t<N>, call_construction>::value) {
|
|
||||||
callconstructfunc = std::move(o);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
insert(std::forward<N>(n), std::move(o));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename N, typename F, meta::disable<is_variable_binding<meta::unqualified_t<F>>> = meta::enabler>
|
template <typename N, typename F, meta::disable<is_variable_binding<meta::unqualified_t<F>>> = meta::enabler>
|
||||||
|
|
856
sol/traits.hpp
856
sol/traits.hpp
|
@ -1,428 +1,428 @@
|
||||||
// The MIT License (MIT)
|
// The MIT License (MIT)
|
||||||
|
|
||||||
// Copyright (c) 2013-2016 Rapptz, ThePhD and contributors
|
// Copyright (c) 2013-2016 Rapptz, ThePhD and contributors
|
||||||
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
// 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
|
// this software and associated documentation files (the "Software"), to deal in
|
||||||
// the Software without restriction, including without limitation the rights to
|
// the Software without restriction, including without limitation the rights to
|
||||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
// 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,
|
// the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
// subject to the following conditions:
|
// subject to the following conditions:
|
||||||
|
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// copies or substantial portions of the Software.
|
// copies or substantial portions of the Software.
|
||||||
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
// 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
|
// 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
|
// 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.
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
#ifndef SOL_TRAITS_HPP
|
#ifndef SOL_TRAITS_HPP
|
||||||
#define SOL_TRAITS_HPP
|
#define SOL_TRAITS_HPP
|
||||||
|
|
||||||
#include "tuple.hpp"
|
#include "tuple.hpp"
|
||||||
#include "bind_traits.hpp"
|
#include "bind_traits.hpp"
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
namespace sol {
|
namespace sol {
|
||||||
template<std::size_t I>
|
template<std::size_t I>
|
||||||
using index_value = std::integral_constant<std::size_t, I>;
|
using index_value = std::integral_constant<std::size_t, I>;
|
||||||
|
|
||||||
namespace meta {
|
namespace meta {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct identity { typedef T type; };
|
struct identity { typedef T type; };
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
using identity_t = typename identity<T>::type;
|
using identity_t = typename identity<T>::type;
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
struct is_tuple : std::false_type { };
|
struct is_tuple : std::false_type { };
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
struct is_tuple<std::tuple<Args...>> : std::true_type { };
|
struct is_tuple<std::tuple<Args...>> : std::true_type { };
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct is_builtin_type : std::integral_constant<bool, std::is_arithmetic<T>::value || std::is_pointer<T>::value || std::is_array<T>::value> {};
|
struct is_builtin_type : std::integral_constant<bool, std::is_arithmetic<T>::value || std::is_pointer<T>::value || std::is_array<T>::value> {};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct unwrapped {
|
struct unwrapped {
|
||||||
typedef T type;
|
typedef T type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct unwrapped<std::reference_wrapper<T>> {
|
struct unwrapped<std::reference_wrapper<T>> {
|
||||||
typedef T type;
|
typedef T type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
using unwrapped_t = typename unwrapped<T>::type;
|
using unwrapped_t = typename unwrapped<T>::type;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct unwrap_unqualified : unwrapped<unqualified_t<T>> {};
|
struct unwrap_unqualified : unwrapped<unqualified_t<T>> {};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using unwrap_unqualified_t = typename unwrap_unqualified<T>::type;
|
using unwrap_unqualified_t = typename unwrap_unqualified<T>::type;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct remove_member_pointer;
|
struct remove_member_pointer;
|
||||||
|
|
||||||
template<typename R, typename T>
|
template<typename R, typename T>
|
||||||
struct remove_member_pointer<R T::*> {
|
struct remove_member_pointer<R T::*> {
|
||||||
typedef R type;
|
typedef R type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename R, typename T>
|
template<typename R, typename T>
|
||||||
struct remove_member_pointer<R T::* const> {
|
struct remove_member_pointer<R T::* const> {
|
||||||
typedef R type;
|
typedef R type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
using remove_member_pointer_t = remove_member_pointer<T>;
|
using remove_member_pointer_t = remove_member_pointer<T>;
|
||||||
|
|
||||||
template<template<typename...> class Templ, typename T>
|
template<template<typename...> class Templ, typename T>
|
||||||
struct is_specialization_of : std::false_type { };
|
struct is_specialization_of : std::false_type { };
|
||||||
template<typename... T, template<typename...> class Templ>
|
template<typename... T, template<typename...> class Templ>
|
||||||
struct is_specialization_of<Templ, Templ<T...>> : std::true_type { };
|
struct is_specialization_of<Templ, Templ<T...>> : std::true_type { };
|
||||||
|
|
||||||
template<class T, class...>
|
template<class T, class...>
|
||||||
struct all_same : std::true_type { };
|
struct all_same : std::true_type { };
|
||||||
|
|
||||||
template<class T, class U, class... Args>
|
template<class T, class U, class... Args>
|
||||||
struct all_same<T, U, Args...> : std::integral_constant <bool, std::is_same<T, U>::value && all_same<T, Args...>::value> { };
|
struct all_same<T, U, Args...> : std::integral_constant <bool, std::is_same<T, U>::value && all_same<T, Args...>::value> { };
|
||||||
|
|
||||||
template<class T, class...>
|
template<class T, class...>
|
||||||
struct any_same : std::false_type { };
|
struct any_same : std::false_type { };
|
||||||
|
|
||||||
template<class T, class U, class... Args>
|
template<class T, class U, class... Args>
|
||||||
struct any_same<T, U, Args...> : std::integral_constant <bool, std::is_same<T, U>::value || any_same<T, Args...>::value> { };
|
struct any_same<T, U, Args...> : std::integral_constant <bool, std::is_same<T, U>::value || any_same<T, Args...>::value> { };
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
using invoke_t = typename T::type;
|
using invoke_t = typename T::type;
|
||||||
|
|
||||||
template<bool B>
|
template<bool B>
|
||||||
using boolean = std::integral_constant<bool, B>;
|
using boolean = std::integral_constant<bool, B>;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
using neg = boolean<!T::value>;
|
using neg = boolean<!T::value>;
|
||||||
|
|
||||||
template<typename Condition, typename Then, typename Else>
|
template<typename Condition, typename Then, typename Else>
|
||||||
using condition = std::conditional_t<Condition::value, Then, Else>;
|
using condition = std::conditional_t<Condition::value, Then, Else>;
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
struct all : boolean<true> {};
|
struct all : boolean<true> {};
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
struct all<T, Args...> : condition<T, all<Args...>, boolean<false>> {};
|
struct all<T, Args...> : condition<T, all<Args...>, boolean<false>> {};
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
struct any : boolean<false> {};
|
struct any : boolean<false> {};
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
struct any<T, Args...> : condition<T, boolean<true>, any<Args...>> {};
|
struct any<T, Args...> : condition<T, boolean<true>, any<Args...>> {};
|
||||||
|
|
||||||
enum class enable_t {
|
enum class enable_t {
|
||||||
_
|
_
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr const auto enabler = enable_t::_;
|
constexpr const auto enabler = enable_t::_;
|
||||||
|
|
||||||
template<bool value, typename T = void>
|
template<bool value, typename T = void>
|
||||||
using disable_if_t = std::enable_if_t<!value, T>;
|
using disable_if_t = std::enable_if_t<!value, T>;
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
using enable = std::enable_if_t<all<Args...>::value, enable_t>;
|
using enable = std::enable_if_t<all<Args...>::value, enable_t>;
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
using disable = std::enable_if_t<neg<all<Args...>>::value, enable_t>;
|
using disable = std::enable_if_t<neg<all<Args...>>::value, enable_t>;
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
using disable_any = std::enable_if_t<neg<any<Args...>>::value, enable_t>;
|
using disable_any = std::enable_if_t<neg<any<Args...>>::value, enable_t>;
|
||||||
|
|
||||||
template<typename V, typename... Vs>
|
template<typename V, typename... Vs>
|
||||||
struct find_in_pack_v : boolean<false> { };
|
struct find_in_pack_v : boolean<false> { };
|
||||||
|
|
||||||
template<typename V, typename Vs1, typename... Vs>
|
template<typename V, typename Vs1, typename... Vs>
|
||||||
struct find_in_pack_v<V, Vs1, Vs...> : any<boolean<(V::value == Vs1::value)>, find_in_pack_v<V, Vs...>> { };
|
struct find_in_pack_v<V, Vs1, Vs...> : any<boolean<(V::value == Vs1::value)>, find_in_pack_v<V, Vs...>> { };
|
||||||
|
|
||||||
namespace meta_detail {
|
namespace meta_detail {
|
||||||
template<std::size_t I, typename T, typename... Args>
|
template<std::size_t I, typename T, typename... Args>
|
||||||
struct index_in_pack : std::integral_constant<std::size_t, SIZE_MAX> { };
|
struct index_in_pack : std::integral_constant<std::size_t, SIZE_MAX> { };
|
||||||
|
|
||||||
template<std::size_t I, typename T, typename T1, typename... Args>
|
template<std::size_t I, typename T, typename T1, typename... Args>
|
||||||
struct index_in_pack<I, T, T1, Args...> : std::conditional_t<std::is_same<T, T1>::value, std::integral_constant<std::ptrdiff_t, I>, index_in_pack<I + 1, T, Args...>> { };
|
struct index_in_pack<I, T, T1, Args...> : std::conditional_t<std::is_same<T, T1>::value, std::integral_constant<std::ptrdiff_t, I>, index_in_pack<I + 1, T, Args...>> { };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
struct index_in_pack : meta_detail::index_in_pack<0, T, Args...> { };
|
struct index_in_pack : meta_detail::index_in_pack<0, T, Args...> { };
|
||||||
|
|
||||||
template<typename T, typename List>
|
template<typename T, typename List>
|
||||||
struct index_in : meta_detail::index_in_pack<0, T, List> { };
|
struct index_in : meta_detail::index_in_pack<0, T, List> { };
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
struct index_in<T, types<Args...>> : meta_detail::index_in_pack<0, T, Args...> { };
|
struct index_in<T, types<Args...>> : meta_detail::index_in_pack<0, T, Args...> { };
|
||||||
|
|
||||||
template<std::size_t I, typename... Args>
|
template<std::size_t I, typename... Args>
|
||||||
struct at_in_pack {};
|
struct at_in_pack {};
|
||||||
|
|
||||||
template<std::size_t I, typename... Args>
|
template<std::size_t I, typename... Args>
|
||||||
using at_in_pack_t = typename at_in_pack<I, Args...>::type;
|
using at_in_pack_t = typename at_in_pack<I, Args...>::type;
|
||||||
|
|
||||||
template<std::size_t I, typename Arg, typename... Args>
|
template<std::size_t I, typename Arg, typename... Args>
|
||||||
struct at_in_pack<I, Arg, Args...> : std::conditional<I == 0, Arg, at_in_pack_t<I - 1, Args...>> {};
|
struct at_in_pack<I, Arg, Args...> : std::conditional<I == 0, Arg, at_in_pack_t<I - 1, Args...>> {};
|
||||||
|
|
||||||
template<typename Arg, typename... Args>
|
template<typename Arg, typename... Args>
|
||||||
struct at_in_pack<0, Arg, Args...> { typedef Arg type; };
|
struct at_in_pack<0, Arg, Args...> { typedef Arg type; };
|
||||||
|
|
||||||
namespace meta_detail {
|
namespace meta_detail {
|
||||||
template<std::size_t Limit, std::size_t I, template<typename...> class Pred, typename... Ts>
|
template<std::size_t Limit, std::size_t I, template<typename...> class Pred, typename... Ts>
|
||||||
struct count_for_pack : std::integral_constant<std::size_t, 0> {};
|
struct count_for_pack : std::integral_constant<std::size_t, 0> {};
|
||||||
template<std::size_t Limit, std::size_t I, template<typename...> class Pred, typename T, typename... Ts>
|
template<std::size_t Limit, std::size_t I, template<typename...> class Pred, typename T, typename... Ts>
|
||||||
struct count_for_pack<Limit, I, Pred, T, Ts...> : std::conditional_t < sizeof...(Ts) == 0 || Limit < 2,
|
struct count_for_pack<Limit, I, Pred, T, Ts...> : std::conditional_t < sizeof...(Ts) == 0 || Limit < 2,
|
||||||
std::integral_constant<std::size_t, I + static_cast<std::size_t>(Limit != 0 && Pred<T>::value)>,
|
std::integral_constant<std::size_t, I + static_cast<std::size_t>(Limit != 0 && Pred<T>::value)>,
|
||||||
count_for_pack<Limit - 1, I + static_cast<std::size_t>(Pred<T>::value), Pred, Ts...>
|
count_for_pack<Limit - 1, I + static_cast<std::size_t>(Pred<T>::value), Pred, Ts...>
|
||||||
> { };
|
> { };
|
||||||
template<std::size_t I, template<typename...> class Pred, typename... Ts>
|
template<std::size_t I, template<typename...> class Pred, typename... Ts>
|
||||||
struct count_2_for_pack : std::integral_constant<std::size_t, 0> {};
|
struct count_2_for_pack : std::integral_constant<std::size_t, 0> {};
|
||||||
template<std::size_t I, template<typename...> class Pred, typename T, typename U, typename... Ts>
|
template<std::size_t I, template<typename...> class Pred, typename T, typename U, typename... Ts>
|
||||||
struct count_2_for_pack<I, Pred, T, U, Ts...> : std::conditional_t<sizeof...(Ts) == 0,
|
struct count_2_for_pack<I, Pred, T, U, Ts...> : std::conditional_t<sizeof...(Ts) == 0,
|
||||||
std::integral_constant<std::size_t, I + static_cast<std::size_t>(Pred<T>::value)>,
|
std::integral_constant<std::size_t, I + static_cast<std::size_t>(Pred<T>::value)>,
|
||||||
count_2_for_pack<I + static_cast<std::size_t>(Pred<T>::value), Pred, Ts...>
|
count_2_for_pack<I + static_cast<std::size_t>(Pred<T>::value), Pred, Ts...>
|
||||||
> { };
|
> { };
|
||||||
} // meta_detail
|
} // meta_detail
|
||||||
|
|
||||||
template<template<typename...> class Pred, typename... Ts>
|
template<template<typename...> class Pred, typename... Ts>
|
||||||
struct count_for_pack : meta_detail::count_for_pack<sizeof...(Ts), 0, Pred, Ts...> { };
|
struct count_for_pack : meta_detail::count_for_pack<sizeof...(Ts), 0, Pred, Ts...> { };
|
||||||
|
|
||||||
template<template<typename...> class Pred, typename List>
|
template<template<typename...> class Pred, typename List>
|
||||||
struct count_for;
|
struct count_for;
|
||||||
|
|
||||||
template<template<typename...> class Pred, typename... Args>
|
template<template<typename...> class Pred, typename... Args>
|
||||||
struct count_for<Pred, types<Args...>> : count_for_pack<Pred, Args...> {};
|
struct count_for<Pred, types<Args...>> : count_for_pack<Pred, Args...> {};
|
||||||
|
|
||||||
template<std::size_t Limit, template<typename...> class Pred, typename... Ts>
|
template<std::size_t Limit, template<typename...> class Pred, typename... Ts>
|
||||||
struct count_for_to_pack : meta_detail::count_for_pack<Limit, 0, Pred, Ts...> { };
|
struct count_for_to_pack : meta_detail::count_for_pack<Limit, 0, Pred, Ts...> { };
|
||||||
|
|
||||||
template<template<typename...> class Pred, typename... Ts>
|
template<template<typename...> class Pred, typename... Ts>
|
||||||
struct count_2_for_pack : meta_detail::count_2_for_pack<0, Pred, Ts...> { };
|
struct count_2_for_pack : meta_detail::count_2_for_pack<0, Pred, Ts...> { };
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
struct return_type {
|
struct return_type {
|
||||||
typedef std::tuple<Args...> type;
|
typedef std::tuple<Args...> type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct return_type<T> {
|
struct return_type<T> {
|
||||||
typedef T type;
|
typedef T type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct return_type<> {
|
struct return_type<> {
|
||||||
typedef void type;
|
typedef void type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
using return_type_t = typename return_type<Args...>::type;
|
using return_type_t = typename return_type<Args...>::type;
|
||||||
|
|
||||||
namespace meta_detail {
|
namespace meta_detail {
|
||||||
template <typename> struct always_true : std::true_type {};
|
template <typename> struct always_true : std::true_type {};
|
||||||
struct is_invokable_tester {
|
struct is_invokable_tester {
|
||||||
template <typename Fun, typename... Args>
|
template <typename Fun, typename... Args>
|
||||||
always_true<decltype(std::declval<Fun>()(std::declval<Args>()...))> static test(int);
|
always_true<decltype(std::declval<Fun>()(std::declval<Args>()...))> static test(int);
|
||||||
template <typename...>
|
template <typename...>
|
||||||
std::false_type static test(...);
|
std::false_type static test(...);
|
||||||
};
|
};
|
||||||
} // meta_detail
|
} // meta_detail
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct is_invokable;
|
struct is_invokable;
|
||||||
template <typename Fun, typename... Args>
|
template <typename Fun, typename... Args>
|
||||||
struct is_invokable<Fun(Args...)> : decltype(meta_detail::is_invokable_tester::test<Fun, Args...>(0)) {};
|
struct is_invokable<Fun(Args...)> : decltype(meta_detail::is_invokable_tester::test<Fun, Args...>(0)) {};
|
||||||
|
|
||||||
namespace meta_detail {
|
namespace meta_detail {
|
||||||
|
|
||||||
template<typename T, bool isclass = std::is_class<unqualified_t<T>>::value>
|
template<typename T, bool isclass = std::is_class<unqualified_t<T>>::value>
|
||||||
struct is_callable : std::is_function<std::remove_pointer_t<T>> {};
|
struct is_callable : std::is_function<std::remove_pointer_t<T>> {};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_callable<T, true> {
|
struct is_callable<T, true> {
|
||||||
using yes = char;
|
using yes = char;
|
||||||
using no = struct { char s[2]; };
|
using no = struct { char s[2]; };
|
||||||
|
|
||||||
struct F { void operator()(); };
|
struct F { void operator()(); };
|
||||||
struct Derived : T, F {};
|
struct Derived : T, F {};
|
||||||
template<typename U, U> struct Check;
|
template<typename U, U> struct Check;
|
||||||
|
|
||||||
template<typename V>
|
template<typename V>
|
||||||
static no test(Check<void (F::*)(), &V::operator()>*);
|
static no test(Check<void (F::*)(), &V::operator()>*);
|
||||||
|
|
||||||
template<typename>
|
template<typename>
|
||||||
static yes test(...);
|
static yes test(...);
|
||||||
|
|
||||||
static const bool value = sizeof(test<Derived>(0)) == sizeof(yes);
|
static const bool value = sizeof(test<Derived>(0)) == sizeof(yes);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct has_begin_end_impl {
|
struct has_begin_end_impl {
|
||||||
template<typename T, typename U = unqualified_t<T>,
|
template<typename T, typename U = unqualified_t<T>,
|
||||||
typename B = decltype(std::declval<U&>().begin()),
|
typename B = decltype(std::declval<U&>().begin()),
|
||||||
typename E = decltype(std::declval<U&>().end())>
|
typename E = decltype(std::declval<U&>().end())>
|
||||||
static std::true_type test(int);
|
static std::true_type test(int);
|
||||||
|
|
||||||
template<typename...>
|
template<typename...>
|
||||||
static std::false_type test(...);
|
static std::false_type test(...);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct has_key_value_pair_impl {
|
struct has_key_value_pair_impl {
|
||||||
template<typename T, typename U = unqualified_t<T>,
|
template<typename T, typename U = unqualified_t<T>,
|
||||||
typename V = typename U::value_type,
|
typename V = typename U::value_type,
|
||||||
typename F = decltype(std::declval<V&>().first),
|
typename F = decltype(std::declval<V&>().first),
|
||||||
typename S = decltype(std::declval<V&>().second)>
|
typename S = decltype(std::declval<V&>().second)>
|
||||||
static std::true_type test(int);
|
static std::true_type test(int);
|
||||||
|
|
||||||
template<typename...>
|
template<typename...>
|
||||||
static std::false_type test(...);
|
static std::false_type test(...);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, typename U = T, typename = decltype(std::declval<T&>() < std::declval<U&>())>
|
template <typename T, typename U = T, typename = decltype(std::declval<T&>() < std::declval<U&>())>
|
||||||
std::true_type supports_op_less_test(const T&);
|
std::true_type supports_op_less_test(const T&);
|
||||||
std::false_type supports_op_less_test(...);
|
std::false_type supports_op_less_test(...);
|
||||||
template <typename T, typename U = T, typename = decltype(std::declval<T&>() == std::declval<U&>())>
|
template <typename T, typename U = T, typename = decltype(std::declval<T&>() == std::declval<U&>())>
|
||||||
std::true_type supports_op_equal_test(const T&);
|
std::true_type supports_op_equal_test(const T&);
|
||||||
std::false_type supports_op_equal_test(...);
|
std::false_type supports_op_equal_test(...);
|
||||||
template <typename T, typename U = T, typename = decltype(std::declval<T&>() <= std::declval<U&>())>
|
template <typename T, typename U = T, typename = decltype(std::declval<T&>() <= std::declval<U&>())>
|
||||||
std::true_type supports_op_less_equal_test(const T&);
|
std::true_type supports_op_less_equal_test(const T&);
|
||||||
std::false_type supports_op_less_equal_test(...);
|
std::false_type supports_op_less_equal_test(...);
|
||||||
|
|
||||||
} // meta_detail
|
} // meta_detail
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using supports_op_less = decltype(meta_detail::supports_op_less_test(std::declval<T&>()));
|
using supports_op_less = decltype(meta_detail::supports_op_less_test(std::declval<T&>()));
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using supports_op_equal = decltype(meta_detail::supports_op_equal_test(std::declval<T&>()));
|
using supports_op_equal = decltype(meta_detail::supports_op_equal_test(std::declval<T&>()));
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using supports_op_less_equal = decltype(meta_detail::supports_op_less_equal_test(std::declval<T&>()));
|
using supports_op_less_equal = decltype(meta_detail::supports_op_less_equal_test(std::declval<T&>()));
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_callable : boolean<meta_detail::is_callable<T>::value> {};
|
struct is_callable : boolean<meta_detail::is_callable<T>::value> {};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct has_begin_end : decltype(meta_detail::has_begin_end_impl::test<T>(0)) {};
|
struct has_begin_end : decltype(meta_detail::has_begin_end_impl::test<T>(0)) {};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct has_key_value_pair : decltype(meta_detail::has_key_value_pair_impl::test<T>(0)) {};
|
struct has_key_value_pair : decltype(meta_detail::has_key_value_pair_impl::test<T>(0)) {};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using is_string_constructible = any<std::is_same<unqualified_t<T>, const char*>, std::is_same<unqualified_t<T>, char>, std::is_same<unqualified_t<T>, std::string>, std::is_same<unqualified_t<T>, std::initializer_list<char>>>;
|
using is_string_constructible = any<std::is_same<unqualified_t<T>, const char*>, std::is_same<unqualified_t<T>, char>, std::is_same<unqualified_t<T>, std::string>, std::is_same<unqualified_t<T>, std::initializer_list<char>>>;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using is_c_str = any<
|
using is_c_str = any<
|
||||||
std::is_same<std::decay_t<unqualified_t<T>>, const char*>,
|
std::is_same<std::decay_t<unqualified_t<T>>, const char*>,
|
||||||
std::is_same<std::decay_t<unqualified_t<T>>, char*>,
|
std::is_same<std::decay_t<unqualified_t<T>>, char*>,
|
||||||
std::is_same<unqualified_t<T>, std::string>
|
std::is_same<unqualified_t<T>, std::string>
|
||||||
>;
|
>;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct is_move_only : all<
|
struct is_move_only : all<
|
||||||
neg<std::is_reference<T>>,
|
neg<std::is_reference<T>>,
|
||||||
neg<std::is_copy_constructible<unqualified_t<T>>>,
|
neg<std::is_copy_constructible<unqualified_t<T>>>,
|
||||||
std::is_move_constructible<unqualified_t<T>>
|
std::is_move_constructible<unqualified_t<T>>
|
||||||
> {};
|
> {};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using is_not_move_only = neg<is_move_only<T>>;
|
using is_not_move_only = neg<is_move_only<T>>;
|
||||||
|
|
||||||
namespace meta_detail {
|
namespace meta_detail {
|
||||||
template <typename T, meta::disable<meta::is_specialization_of<std::tuple, meta::unqualified_t<T>>> = meta::enabler>
|
template <typename T, meta::disable<meta::is_specialization_of<std::tuple, meta::unqualified_t<T>>> = meta::enabler>
|
||||||
decltype(auto) force_tuple(T&& x) {
|
decltype(auto) force_tuple(T&& x) {
|
||||||
return std::forward_as_tuple(std::forward<T>(x));
|
return std::forward_as_tuple(std::forward<T>(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, meta::enable<meta::is_specialization_of<std::tuple, meta::unqualified_t<T>>> = meta::enabler>
|
template <typename T, meta::enable<meta::is_specialization_of<std::tuple, meta::unqualified_t<T>>> = meta::enabler>
|
||||||
decltype(auto) force_tuple(T&& x) {
|
decltype(auto) force_tuple(T&& x) {
|
||||||
return std::forward<T>(x);
|
return std::forward<T>(x);
|
||||||
}
|
}
|
||||||
} // meta_detail
|
} // meta_detail
|
||||||
|
|
||||||
template <typename... X>
|
template <typename... X>
|
||||||
decltype(auto) tuplefy(X&&... x) {
|
decltype(auto) tuplefy(X&&... x) {
|
||||||
return std::tuple_cat(meta_detail::force_tuple(std::forward<X>(x))...);
|
return std::tuple_cat(meta_detail::force_tuple(std::forward<X>(x))...);
|
||||||
}
|
}
|
||||||
} // meta
|
} // meta
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template <std::size_t I, typename Tuple>
|
template <std::size_t I, typename Tuple>
|
||||||
decltype(auto) forward_get(Tuple&& tuple) {
|
decltype(auto) forward_get(Tuple&& tuple) {
|
||||||
return std::forward<meta::tuple_element_t<I, Tuple>>(std::get<I>(tuple));
|
return std::forward<meta::tuple_element_t<I, Tuple>>(std::get<I>(tuple));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <std::size_t... I, typename Tuple>
|
template <std::size_t... I, typename Tuple>
|
||||||
auto forward_tuple_impl(std::index_sequence<I...>, Tuple&& tuple) -> decltype(std::tuple<decltype(forward_get<I>(tuple))...>(forward_get<I>(tuple)...)) {
|
auto forward_tuple_impl(std::index_sequence<I...>, Tuple&& tuple) -> decltype(std::tuple<decltype(forward_get<I>(tuple))...>(forward_get<I>(tuple)...)) {
|
||||||
return std::tuple<decltype(forward_get<I>(tuple))...>(std::move(std::get<I>(tuple))...);
|
return std::tuple<decltype(forward_get<I>(tuple))...>(std::move(std::get<I>(tuple))...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Tuple>
|
template <typename Tuple>
|
||||||
auto forward_tuple(Tuple&& tuple) {
|
auto forward_tuple(Tuple&& tuple) {
|
||||||
auto x = forward_tuple_impl(std::make_index_sequence<std::tuple_size<meta::unqualified_t<Tuple>>::value>(), std::forward<Tuple>(tuple));
|
auto x = forward_tuple_impl(std::make_index_sequence<std::tuple_size<meta::unqualified_t<Tuple>>::value>(), std::forward<Tuple>(tuple));
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
auto unwrap(T&& item) -> decltype(std::forward<T>(item)) {
|
auto unwrap(T&& item) -> decltype(std::forward<T>(item)) {
|
||||||
return std::forward<T>(item);
|
return std::forward<T>(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T& unwrap(std::reference_wrapper<T> arg) {
|
T& unwrap(std::reference_wrapper<T> arg) {
|
||||||
return arg.get();
|
return arg.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
auto deref(T&& item) -> decltype(std::forward<T>(item)) {
|
auto deref(T&& item) -> decltype(std::forward<T>(item)) {
|
||||||
return std::forward<T>(item);
|
return std::forward<T>(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline T& deref(T* item) {
|
inline T& deref(T* item) {
|
||||||
return *item;
|
return *item;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename Dx>
|
template<typename T, typename Dx>
|
||||||
inline std::add_lvalue_reference_t<T> deref(std::unique_ptr<T, Dx>& item) {
|
inline std::add_lvalue_reference_t<T> deref(std::unique_ptr<T, Dx>& item) {
|
||||||
return *item;
|
return *item;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline std::add_lvalue_reference_t<T> deref(std::shared_ptr<T>& item) {
|
inline std::add_lvalue_reference_t<T> deref(std::shared_ptr<T>& item) {
|
||||||
return *item;
|
return *item;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename Dx>
|
template<typename T, typename Dx>
|
||||||
inline std::add_lvalue_reference_t<T> deref(const std::unique_ptr<T, Dx>& item) {
|
inline std::add_lvalue_reference_t<T> deref(const std::unique_ptr<T, Dx>& item) {
|
||||||
return *item;
|
return *item;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline std::add_lvalue_reference_t<T> deref(const std::shared_ptr<T>& item) {
|
inline std::add_lvalue_reference_t<T> deref(const std::shared_ptr<T>& item) {
|
||||||
return *item;
|
return *item;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline T* ptr(T& val) {
|
inline T* ptr(T& val) {
|
||||||
return std::addressof(val);
|
return std::addressof(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline T* ptr(std::reference_wrapper<T> val) {
|
inline T* ptr(std::reference_wrapper<T> val) {
|
||||||
return std::addressof(val.get());
|
return std::addressof(val.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline T* ptr(T* val) {
|
inline T* ptr(T* val) {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
} // detail
|
} // detail
|
||||||
} // sol
|
} // sol
|
||||||
|
|
||||||
#endif // SOL_TRAITS_HPP
|
#endif // SOL_TRAITS_HPP
|
||||||
|
|
|
@ -461,3 +461,29 @@ TEST_CASE("usertype/simple-table-append", "Ensure that appending to the meta tab
|
||||||
lua.script("assert(ua:func() == 5000)");
|
lua.script("assert(ua:func() == 5000)");
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("usertype/simple-class-propogation", "make sure methods and variables from base classes work properly in SAFE_USERTYPE mode") {
|
||||||
|
class A {
|
||||||
|
public:
|
||||||
|
int var = 200;
|
||||||
|
int thing() const { return 123; }
|
||||||
|
};
|
||||||
|
|
||||||
|
class B : public A {
|
||||||
|
};
|
||||||
|
|
||||||
|
sol::state lua;
|
||||||
|
lua.open_libraries(sol::lib::base);
|
||||||
|
|
||||||
|
lua.new_simple_usertype<B>("B",
|
||||||
|
sol::default_constructor,
|
||||||
|
"thing", &B::thing,
|
||||||
|
"var", &B::var
|
||||||
|
);
|
||||||
|
|
||||||
|
lua.script(R"(
|
||||||
|
b = B.new()
|
||||||
|
print(b.var)
|
||||||
|
b:thing()
|
||||||
|
)");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user