mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
VC++ is a butt, but this Closes #91
It prepares for #97 as well, and blocks out #95 until I can be assed Now, it's either performance or handling sol::property ...
This commit is contained in:
parent
96f231a183
commit
3b81a7c85f
@ -71,7 +71,7 @@ struct pusher<function_sig<Sigs...>> {
|
||||
|
||||
template <typename R, typename... A, typename Fx, typename... Args>
|
||||
static void select_convertible(types<R(A...)> t, lua_State* L, Fx&& fx, Args&&... args) {
|
||||
typedef std::decay_t<meta::Unwrapped<meta::Unqualified<Fx>>> raw_fx_t;
|
||||
typedef std::decay_t<meta::unwrapped_t<meta::unqualified_t<Fx>>> raw_fx_t;
|
||||
typedef R(* fx_ptr_t)(A...);
|
||||
typedef std::is_convertible<raw_fx_t, fx_ptr_t> is_convertible;
|
||||
select_convertible(is_convertible(), t, L, std::forward<Fx>(fx), std::forward<Args>(args)...);
|
||||
@ -79,14 +79,14 @@ struct pusher<function_sig<Sigs...>> {
|
||||
|
||||
template <typename Fx, typename... Args>
|
||||
static void select_convertible(types<>, lua_State* L, Fx&& fx, Args&&... args) {
|
||||
typedef meta::function_signature_t<meta::Unwrapped<meta::Unqualified<Fx>>> Sig;
|
||||
typedef meta::function_signature_t<meta::unwrapped_t<meta::unqualified_t<Fx>>> Sig;
|
||||
select_convertible(types<Sig>(), L, std::forward<Fx>(fx), 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;
|
||||
std::unique_ptr<function_detail::base_function> sptr = std::make_unique<function_detail::member_variable<meta::Unqualified<T>, clean_fx>>(std::forward<Fx>(fx), std::forward<T>(obj), std::forward<Args>(args)... );
|
||||
std::unique_ptr<function_detail::base_function> sptr = std::make_unique<function_detail::member_variable<meta::unqualified_t<T>, clean_fx>>(std::forward<Fx>(fx), std::forward<T>(obj), std::forward<Args>(args)... );
|
||||
set_fx(L, std::move(sptr));
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ struct pusher<function_sig<Sigs...>> {
|
||||
typedef std::decay_t<Fx> dFx;
|
||||
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_variable<std::decay_t<decltype(*userptr)>, meta::Unqualified<Fx>>::call;
|
||||
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);
|
||||
upvalues += stack::push(L, light_userdata_value(static_cast<void*>(userptr)));
|
||||
@ -109,13 +109,13 @@ struct pusher<function_sig<Sigs...>> {
|
||||
|
||||
template <typename Fx, typename T, typename... Args>
|
||||
static void select_member_variable(std::true_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
|
||||
typedef meta::Bool<meta::is_specialization_of<std::reference_wrapper, meta::Unqualified<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)...);
|
||||
}
|
||||
|
||||
template <typename Fx>
|
||||
static void select_member_variable(std::true_type, lua_State* L, Fx&& fx) {
|
||||
typedef typename meta::bind_traits<meta::Unqualified<Fx>>::object_type C;
|
||||
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);
|
||||
stack::push(L, c_closure(freefunc, upvalues));
|
||||
@ -124,7 +124,7 @@ struct pusher<function_sig<Sigs...>> {
|
||||
template <typename Fx, typename T, typename... Args>
|
||||
static void select_reference_member_function(std::false_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
|
||||
typedef std::remove_pointer_t<std::decay_t<Fx>> clean_fx;
|
||||
std::unique_ptr<function_detail::base_function> sptr = std::make_unique<function_detail::member_function<meta::Unwrapped<meta::Unqualified<T>>, clean_fx>>(std::forward<Fx>(fx), std::forward<T>(obj), std::forward<Args>(args)... );
|
||||
std::unique_ptr<function_detail::base_function> sptr = std::make_unique<function_detail::member_function<meta::unwrapped_t<meta::unqualified_t<T>>, clean_fx>>(std::forward<Fx>(fx), std::forward<T>(obj), std::forward<Args>(args)... );
|
||||
set_fx(L, std::move(sptr));
|
||||
}
|
||||
|
||||
@ -133,7 +133,7 @@ struct pusher<function_sig<Sigs...>> {
|
||||
typedef std::decay_t<Fx> dFx;
|
||||
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<Fx>>::call;
|
||||
lua_CFunction freefunc = &function_detail::upvalue_member_function<std::decay_t<decltype(*userptr)>, meta::unqualified_t<Fx>>::call;
|
||||
|
||||
int upvalues = stack::stack_detail::push_as_upvalues(L, memfxptr);
|
||||
upvalues += stack::push(L, light_userdata_value(static_cast<void*>(userptr)));
|
||||
@ -142,18 +142,18 @@ struct pusher<function_sig<Sigs...>> {
|
||||
|
||||
template <typename Fx, typename... Args>
|
||||
static void select_member_function(std::false_type, lua_State* L, Fx&& fx, Args&&... args) {
|
||||
select_member_variable(std::is_member_object_pointer<meta::Unqualified<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>
|
||||
static void select_member_function(std::true_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) {
|
||||
typedef meta::Bool<meta::is_specialization_of<std::reference_wrapper, meta::Unqualified<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)...);
|
||||
}
|
||||
|
||||
template <typename Fx>
|
||||
static void select_member_function(std::true_type, lua_State* L, Fx&& fx) {
|
||||
typedef typename meta::bind_traits<meta::Unqualified<Fx>>::object_type C;
|
||||
typedef typename meta::bind_traits<meta::unqualified_t<Fx>>::object_type 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));
|
||||
@ -161,7 +161,7 @@ struct pusher<function_sig<Sigs...>> {
|
||||
|
||||
template <typename Fx, typename... 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<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>
|
||||
@ -179,7 +179,7 @@ struct pusher<function_sig<Sigs...>> {
|
||||
|
||||
template <typename Fx, typename... Args>
|
||||
static void select(lua_State* L, Fx&& fx, Args&&... args) {
|
||||
select_function(std::is_function<meta::Unqualified<Fx>>(), L, std::forward<Fx>(fx), std::forward<Args>(args)...);
|
||||
select_function(std::is_function<meta::unqualified_t<Fx>>(), L, std::forward<Fx>(fx), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
static void set_fx(lua_State* L, std::unique_ptr<function_detail::base_function> luafunc) {
|
||||
@ -230,7 +230,7 @@ struct pusher<Signature, std::enable_if_t<std::is_member_pointer<Signature>::val
|
||||
};
|
||||
|
||||
template<typename Signature>
|
||||
struct pusher<Signature, std::enable_if_t<meta::And<std::is_function<Signature>, meta::Not<std::is_same<Signature, lua_CFunction>>, meta::Not<std::is_same<Signature, std::remove_pointer_t<lua_CFunction>>>>::value>> {
|
||||
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));
|
||||
|
@ -29,7 +29,7 @@ namespace function_detail {
|
||||
template<typename Function>
|
||||
struct upvalue_free_function {
|
||||
typedef std::remove_pointer_t<std::decay_t<Function>> function_type;
|
||||
typedef meta::bind_traits<function_type> traits_type;
|
||||
typedef lua_bind_traits<function_type> traits_type;
|
||||
|
||||
static int real_call(lua_State* L) {
|
||||
auto udata = stack::stack_detail::get_as_upvalues<function_type*>(L);
|
||||
@ -50,7 +50,7 @@ struct upvalue_free_function {
|
||||
template<typename T, typename Function>
|
||||
struct upvalue_member_function {
|
||||
typedef std::remove_pointer_t<std::decay_t<Function>> function_type;
|
||||
typedef meta::bind_traits<function_type> traits_type;
|
||||
typedef lua_bind_traits<function_type> traits_type;
|
||||
|
||||
static int real_call(lua_State* L) {
|
||||
// Layout:
|
||||
@ -104,7 +104,7 @@ int set_variable(std::false_type, lua_State* L, M&, V&) {
|
||||
template<typename T, typename Function>
|
||||
struct upvalue_member_variable {
|
||||
typedef std::remove_pointer_t<std::decay_t<Function>> function_type;
|
||||
typedef meta::bind_traits<function_type> traits_type;
|
||||
typedef lua_bind_traits<function_type> traits_type;
|
||||
|
||||
static int real_call(lua_State* L) {
|
||||
// Layout:
|
||||
@ -121,7 +121,7 @@ struct upvalue_member_variable {
|
||||
stack::push(L, (mem.*var));
|
||||
return 1;
|
||||
case 1:
|
||||
set_variable<1, typename traits_type::return_type>(meta::Not<std::is_const<typename traits_type::return_type>>(), L, mem, var);
|
||||
set_variable<1, typename traits_type::return_type>(meta::neg<std::is_const<typename traits_type::return_type>>(), L, mem, var);
|
||||
return 0;
|
||||
default:
|
||||
return luaL_error(L, "sol: incorrect number of arguments to member variable function");
|
||||
@ -140,7 +140,7 @@ struct upvalue_member_variable {
|
||||
template<typename T, typename Function>
|
||||
struct upvalue_this_member_function {
|
||||
typedef std::remove_pointer_t<std::decay_t<Function>> function_type;
|
||||
typedef meta::bind_traits<function_type> traits_type;
|
||||
typedef lua_bind_traits<function_type> traits_type;
|
||||
|
||||
static int real_call(lua_State* L) {
|
||||
// Layout:
|
||||
@ -167,7 +167,7 @@ struct upvalue_this_member_function {
|
||||
template<typename T, typename Function>
|
||||
struct upvalue_this_member_variable {
|
||||
typedef std::remove_pointer_t<std::decay_t<Function>> function_type;
|
||||
typedef meta::bind_traits<function_type> traits_type;
|
||||
typedef lua_bind_traits<function_type> traits_type;
|
||||
|
||||
static int real_call(lua_State* L) {
|
||||
// Layout:
|
||||
@ -181,7 +181,7 @@ struct upvalue_this_member_variable {
|
||||
stack::push(L, (mem.*var));
|
||||
return 1;
|
||||
case 2:
|
||||
set_variable<2, typename traits_type::return_type>(meta::Not<std::is_const<typename traits_type::return_type>>(), L, mem, var);
|
||||
set_variable<2, typename traits_type::return_type>(meta::neg<std::is_const<typename traits_type::return_type>>(), L, mem, var);
|
||||
return 0;
|
||||
default:
|
||||
return luaL_error(L, "sol: incorrect number of arguments to member variable function");
|
||||
|
@ -51,7 +51,7 @@ struct member_property {
|
||||
|
||||
template <typename T, typename Arg>
|
||||
void operator()(T& mem, Arg&& arg) {
|
||||
write_if(meta::Not<std::is_void<WSig>>(), mem, arg);
|
||||
write_if(meta::neg<std::is_void<WSig>>(), mem, arg);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -72,7 +72,7 @@ struct member_property {
|
||||
|
||||
template <typename T>
|
||||
decltype(auto) operator()(T& mem) {
|
||||
return read_if(meta::Not<std::is_void<RSig>>(), mem);
|
||||
return read_if(meta::neg<std::is_void<RSig>>(), mem);
|
||||
}
|
||||
};
|
||||
|
||||
@ -177,7 +177,7 @@ struct functor {
|
||||
};
|
||||
|
||||
template<typename T, typename Func>
|
||||
struct functor<T, Func, std::enable_if_t<!std::is_member_pointer<Func>::value && std::is_base_of<T, meta::Unqualified<typename meta::bind_traits<Func>::template arg_at<0>>>::value>> {
|
||||
struct functor<T, Func, std::enable_if_t<!std::is_member_pointer<Func>::value && std::is_base_of<T, meta::unqualified_t<typename meta::bind_traits<Func>::template arg_at<0>>>::value>> {
|
||||
typedef meta::bind_traits<Func> traits_type;
|
||||
typedef meta::pop_front_type_t<typename traits_type::args_type> args_type;
|
||||
typedef typename traits_type::return_type return_type;
|
||||
@ -214,8 +214,8 @@ struct functor<T, member_property<RSig, WSig>, C> {
|
||||
typedef meta::pop_front_type_t<typename traits_type::args_type> args_type;
|
||||
typedef std::conditional_t<std::is_void<typename traits_type::return_type>::value, typename traits_type::template arg_at<0>, typename traits_type::return_type> return_type;
|
||||
typedef member_property<RSig, WSig> function_type;
|
||||
typedef meta::Not<std::is_void<RSig>> can_read;
|
||||
typedef meta::Not<std::is_void<WSig>> can_write;
|
||||
typedef meta::neg<std::is_void<RSig>> can_read;
|
||||
typedef meta::neg<std::is_void<WSig>> can_write;
|
||||
static const bool is_free = false;
|
||||
|
||||
T* item;
|
||||
@ -373,7 +373,7 @@ inline int usertype_call(lua_State* L) {
|
||||
|
||||
template<std::size_t I>
|
||||
inline int usertype_gc(lua_State* L) {
|
||||
func_gc<I>(meta::Bool<(I < 1)>(), L);
|
||||
func_gc<I>(meta::boolean<(I < 1)>(), L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ namespace sol {
|
||||
namespace function_detail {
|
||||
template<typename Func>
|
||||
struct free_function : public base_function {
|
||||
typedef meta::Unwrapped<meta::Unqualified<Func>> Function;
|
||||
typedef meta::unwrapped_t<meta::unqualified_t<Func>> Function;
|
||||
typedef meta::function_return_t<Function> return_type;
|
||||
typedef meta::function_args_t<Function> args_types;
|
||||
Function fx;
|
||||
@ -48,7 +48,7 @@ struct free_function : public base_function {
|
||||
|
||||
template<typename Func>
|
||||
struct functor_function : public base_function {
|
||||
typedef meta::Unwrapped<meta::Unqualified<Func>> Function;
|
||||
typedef meta::unwrapped_t<meta::unqualified_t<Func>> Function;
|
||||
typedef decltype(&Function::operator()) function_type;
|
||||
typedef meta::function_return_t<function_type> return_type;
|
||||
typedef meta::function_args_t<function_type> args_types;
|
||||
@ -106,7 +106,7 @@ struct member_variable : public base_function {
|
||||
typedef typename meta::bind_traits<function_type>::args_type args_types;
|
||||
function_type var;
|
||||
T member;
|
||||
typedef std::add_lvalue_reference_t<meta::Unwrapped<std::remove_reference_t<decltype(detail::deref(member))>>> M;
|
||||
typedef std::add_lvalue_reference_t<meta::unwrapped_t<std::remove_reference_t<decltype(detail::deref(member))>>> M;
|
||||
|
||||
template<typename V, typename... Args>
|
||||
member_variable(V&& v, Args&&... args): var(std::forward<V>(v)), member(std::forward<Args>(args)...) {}
|
||||
@ -138,7 +138,7 @@ struct member_variable : public base_function {
|
||||
stack::push(L, (mem.*var));
|
||||
return 1;
|
||||
case 1:
|
||||
return set_variable(meta::Not<std::is_const<return_type>>(), L, mem);
|
||||
return set_variable(meta::neg<std::is_const<return_type>>(), L, mem);
|
||||
default:
|
||||
return luaL_error(L, "sol: incorrect number of arguments to member variable function");
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ namespace sol {
|
||||
namespace function_detail {
|
||||
namespace internals {
|
||||
template <typename T>
|
||||
struct overload_traits : meta::bind_traits<T> {
|
||||
struct overload_traits : lua_bind_traits<T> {
|
||||
static const std::size_t boost = 0;
|
||||
};
|
||||
|
||||
@ -49,20 +49,17 @@ inline int overload_match_arity(types<>, std::index_sequence<>, std::index_seque
|
||||
|
||||
template <typename Fx, typename... Fxs, std::size_t I, std::size_t... In, std::size_t... M, typename Match, typename... Args>
|
||||
inline int overload_match_arity(types<Fx, Fxs...>, std::index_sequence<I, In...>, std::index_sequence<M...>, Match&& matchfx, lua_State* L, int nfxarity, int start, Args&&... args) {
|
||||
typedef overload_traits<meta::Unqualified<Fx>> traits;
|
||||
typedef overload_traits<meta::unqualified_t<Fx>> traits;
|
||||
typedef meta::tuple_types<typename traits::return_type> return_types;
|
||||
typedef typename traits::args_type args_type;
|
||||
typedef typename args_type::indices args_indices;
|
||||
typedef meta::index_in<this_state, args_type> state_index;
|
||||
typedef meta::index_in<variadic_args, args_type> va_pack_index;
|
||||
static const std::size_t arity = traits::arity - static_cast<std::size_t>(state_index::value != SIZE_MAX) - static_cast<std::size_t>(va_pack_index::value != SIZE_MAX);
|
||||
int fxarity = traits::boost + nfxarity;
|
||||
// compile-time eliminate any functions that we know ahead of time are of improper arity
|
||||
if (meta::find_in_pack_v<index_value<arity>, index_value<M>...>::value) {
|
||||
if (meta::find_in_pack_v<index_value<traits::arity>, index_value<M>...>::value) {
|
||||
return overload_match_arity(types<Fxs...>(), std::index_sequence<In...>(), std::index_sequence<M...>(), std::forward<Match>(matchfx), L, nfxarity, start, std::forward<Args>(args)...);
|
||||
}
|
||||
if (arity != fxarity) {
|
||||
return overload_match_arity(types<Fxs...>(), std::index_sequence<In...>(), std::index_sequence<arity, M...>(), std::forward<Match>(matchfx), L, nfxarity, start, std::forward<Args>(args)...);
|
||||
if (traits::arity != fxarity) {
|
||||
return overload_match_arity(types<Fxs...>(), std::index_sequence<In...>(), std::index_sequence<traits::arity, M...>(), std::forward<Match>(matchfx), L, nfxarity, start, std::forward<Args>(args)...);
|
||||
}
|
||||
if (!stack::stack_detail::check_types<true>().check(args_type(), args_indices(), L, start - traits::boost, no_panic)) {
|
||||
return overload_match_arity(types<Fxs...>(), std::index_sequence<In...>(), std::index_sequence<M...>(), std::forward<Match>(matchfx), L, nfxarity, start, std::forward<Args>(args)...);
|
||||
@ -116,10 +113,10 @@ struct usertype_overloaded_function : base_function {
|
||||
|
||||
usertype_overloaded_function(std::tuple<Functions...> set) : overloads(std::move(set)) {}
|
||||
|
||||
template <typename Fx, std::size_t I, typename... R, typename... Args, meta::DisableIf<meta::Bool<Fx::is_free>> = 0>
|
||||
template <typename Fx, std::size_t I, typename... R, typename... Args, meta::disable<meta::boolean<Fx::is_free>> = meta::enabler>
|
||||
int call(types<Fx>, index_value<I>, types<R...> r, types<Args...> a, lua_State* L, int, int start) {
|
||||
auto& func = std::get<I>(overloads);
|
||||
func.item = stack::get<meta::Unwrapped<T>*>(L, 1);
|
||||
func.item = stack::get<meta::unwrapped_t<T>*>(L, 1);
|
||||
#ifdef SOL_SAFE_USERTYPE
|
||||
if (func.item == nullptr) {
|
||||
return luaL_error(L, "sol: received null for 'self' argument (use ':' for accessing member functions)");
|
||||
@ -128,7 +125,7 @@ struct usertype_overloaded_function : base_function {
|
||||
return stack::call_into_lua<0, false>(r, a, L, start, func);
|
||||
}
|
||||
|
||||
template <typename Fx, std::size_t I, typename... R, typename... Args, meta::EnableIf<meta::Bool<Fx::is_free>> = 0>
|
||||
template <typename Fx, std::size_t I, typename... R, typename... Args, meta::enable<meta::boolean<Fx::is_free>> = meta::enabler>
|
||||
int call(types<Fx>, index_value<I>, types<R...> r, types<Args...> a, lua_State* L, int, int start) {
|
||||
auto& func = std::get<I>(overloads);
|
||||
return stack::call_into_lua<0, false>(r, a, L, start - 1, func);
|
||||
|
@ -28,7 +28,7 @@ namespace sol {
|
||||
namespace function_detail {
|
||||
template <typename F, F fx>
|
||||
inline int call_wrapper_variable(std::false_type, lua_State* L) {
|
||||
typedef meta::bind_traits<meta::Unqualified<F>> traits_type;
|
||||
typedef meta::bind_traits<meta::unqualified_t<F>> traits_type;
|
||||
typedef typename traits_type::args_type args_type;
|
||||
typedef meta::tuple_types<typename traits_type::return_type> return_type;
|
||||
return stack::call_into_lua(return_type(), args_type(), L, 1, fx);
|
||||
@ -60,7 +60,7 @@ namespace function_detail {
|
||||
|
||||
template <typename V, V variable>
|
||||
inline int call_wrapper_variable(std::true_type, lua_State* L) {
|
||||
typedef meta::bind_traits<meta::Unqualified<V>> traits_type;
|
||||
typedef meta::bind_traits<meta::unqualified_t<V>> traits_type;
|
||||
typedef typename traits_type::object_type T;
|
||||
typedef typename traits_type::return_type R;
|
||||
auto& mem = stack::get<T>(L, 1);
|
||||
@ -71,7 +71,7 @@ namespace function_detail {
|
||||
stack::push_reference(L, std::forward<decltype(r)>(r));
|
||||
return 1; }
|
||||
case 2:
|
||||
return call_set_variable<R, V, variable>(meta::Not<std::is_const<R>>(), L, mem);
|
||||
return call_set_variable<R, V, variable>(meta::neg<std::is_const<R>>(), L, mem);
|
||||
default:
|
||||
return luaL_error(L, "incorrect number of arguments to member variable function call");
|
||||
}
|
||||
@ -84,7 +84,7 @@ namespace function_detail {
|
||||
|
||||
template <typename F, F fx>
|
||||
inline int call_wrapper_function(std::true_type, lua_State* L) {
|
||||
typedef meta::bind_traits<meta::Unqualified<F>> traits_type;
|
||||
typedef meta::bind_traits<meta::unqualified_t<F>> traits_type;
|
||||
typedef typename traits_type::object_type T;
|
||||
typedef typename traits_type::args_type args_type;
|
||||
typedef typename traits_type::return_type return_type;
|
||||
@ -99,7 +99,7 @@ namespace function_detail {
|
||||
|
||||
template <typename F, F fx>
|
||||
inline int call_wrapper_entry(lua_State* L) {
|
||||
return call_wrapper_function<F, fx>(std::is_member_function_pointer<meta::Unqualified<F>>(), L);
|
||||
return call_wrapper_function<F, fx>(std::is_member_function_pointer<meta::unqualified_t<F>>(), L);
|
||||
}
|
||||
} // function_detail
|
||||
|
||||
|
@ -60,7 +60,7 @@ struct usertype_function : public usertype_function_core<Tp, Function> {
|
||||
usertype_function(Args&&... args): base_t(std::forward<Args>(args)...) {}
|
||||
|
||||
int prelude(lua_State* L) {
|
||||
this->fx.item = stack::get<meta::Unwrapped<T>*>(L, 1);
|
||||
this->fx.item = stack::get<meta::unwrapped_t<T>*>(L, 1);
|
||||
#ifdef SOL_SAFE_USERTYPE
|
||||
if (this->fx.item == nullptr) {
|
||||
return luaL_error(L, "sol: received null for 'self' argument (use ':' for accessing member functions)");
|
||||
@ -136,7 +136,7 @@ struct usertype_variable_function : public usertype_function_core<Tp, Function>
|
||||
case 2:
|
||||
return get_variable(can_read(), L);
|
||||
case 3:
|
||||
return set_variable(meta::Not<std::is_const<return_type>>(), L);
|
||||
return set_variable(meta::neg<std::is_const<return_type>>(), L);
|
||||
default:
|
||||
return luaL_error(L, "sol: cannot get/set userdata member variable with inappropriate number of arguments");
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ namespace sol {
|
||||
|
||||
template<typename T>
|
||||
T get() const {
|
||||
return tagged_get(types<meta::Unqualified<T>>());
|
||||
return tagged_get(types<meta::unqualified_t<T>>());
|
||||
}
|
||||
|
||||
template<typename... Ret, typename... Args>
|
||||
|
@ -55,7 +55,7 @@ private:
|
||||
|
||||
public:
|
||||
basic_object() noexcept = default;
|
||||
template <typename T, meta::EnableIf<meta::Not<std::is_same<meta::Unqualified<T>, basic_object>>, std::is_base_of<base_t, meta::Unqualified<T>>> = 0>
|
||||
template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_object>>, std::is_base_of<base_t, meta::unqualified_t<T>>> = meta::enabler>
|
||||
basic_object(T&& r) : base_t(std::forward<T>(r)) {}
|
||||
basic_object(nil_t r) : base_t(r) {}
|
||||
basic_object(const basic_object&) = default;
|
||||
|
@ -28,7 +28,7 @@ namespace sol {
|
||||
template <typename... Functions>
|
||||
struct overload_set {
|
||||
std::tuple<Functions...> set;
|
||||
template <typename Arg, typename... Args, meta::DisableIf<std::is_same<overload_set, meta::Unqualified<Arg>>> = 0>
|
||||
template <typename Arg, typename... Args, meta::disable<std::is_same<overload_set, meta::unqualified_t<Arg>>> = meta::enabler>
|
||||
overload_set (Arg&& arg, Args&&... args) : set(std::forward<Arg>(arg), std::forward<Args>(args)...) {}
|
||||
overload_set(const overload_set&) = default;
|
||||
overload_set(overload_set&&) = default;
|
||||
|
@ -115,7 +115,7 @@ public:
|
||||
|
||||
template<typename T>
|
||||
T get() const {
|
||||
return tagged_get(types<meta::Unqualified<T>>());
|
||||
return tagged_get(types<meta::unqualified_t<T>>());
|
||||
}
|
||||
|
||||
lua_State* lua_state() const { return L; };
|
||||
|
@ -32,7 +32,7 @@ namespace sol {
|
||||
template<typename Table, typename Key>
|
||||
struct proxy : public proxy_base<proxy<Table, Key>> {
|
||||
private:
|
||||
typedef meta::If<meta::is_specialization_of<std::tuple, Key>, Key, std::tuple<meta::If<std::is_array<meta::Unqualified<Key>>, Key&, meta::Unqualified<Key>>>> key_type;
|
||||
typedef meta::condition<meta::is_specialization_of<std::tuple, Key>, Key, std::tuple<meta::condition<std::is_array<meta::unqualified_t<Key>>, Key&, meta::unqualified_t<Key>>>> key_type;
|
||||
|
||||
template<typename T, std::size_t... I>
|
||||
decltype(auto) tuple_get(std::index_sequence<I...>) const {
|
||||
@ -53,7 +53,7 @@ public:
|
||||
|
||||
template<typename T>
|
||||
proxy& set(T&& item) {
|
||||
tuple_set( std::make_index_sequence<std::tuple_size<meta::Unqualified<key_type>>::value>(), std::forward<T>(item) );
|
||||
tuple_set( std::make_index_sequence<std::tuple_size<meta::unqualified_t<key_type>>::value>(), std::forward<T>(item) );
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -63,19 +63,19 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename U, meta::EnableIf<meta::Function<meta::Unqualified<U>>> = 0>
|
||||
template<typename U, meta::enable<meta::is_callable<meta::unqualified_t<U>>> = meta::enabler>
|
||||
proxy& operator=(U&& other) {
|
||||
return set_function(std::forward<U>(other));
|
||||
}
|
||||
|
||||
template<typename U, meta::DisableIf<meta::Function<meta::Unqualified<U>>> = 0>
|
||||
template<typename U, meta::disable<meta::is_callable<meta::unqualified_t<U>>> = meta::enabler>
|
||||
proxy& operator=(U&& other) {
|
||||
return set(std::forward<U>(other));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
decltype(auto) get() const {
|
||||
return tuple_get<T>( std::make_index_sequence<std::tuple_size<meta::Unqualified<key_type>>::value>() );
|
||||
return tuple_get<T>( std::make_index_sequence<std::tuple_size<meta::unqualified_t<key_type>>::value>() );
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@ -115,7 +115,7 @@ public:
|
||||
|
||||
bool valid () const {
|
||||
stack::push_pop(tbl);
|
||||
auto p = stack::probe_get_field<std::is_same<meta::Unqualified<Table>, global_table>::value>(tbl.lua_state(), key, lua_gettop(tbl.lua_state()));
|
||||
auto p = stack::probe_get_field<std::is_same<meta::unqualified_t<Table>, global_table>::value>(tbl.lua_state(), key, lua_gettop(tbl.lua_state()));
|
||||
lua_pop(tbl.lua_state(), p.levels);
|
||||
return p;
|
||||
}
|
||||
|
@ -34,13 +34,13 @@ struct proxy_base {
|
||||
return super.template get<std::string>();
|
||||
}
|
||||
|
||||
template<typename T, meta::EnableIf<meta::Not<meta::is_string_constructible<T>>, is_proxy_primitive<meta::Unqualified<T>>> = 0>
|
||||
template<typename T, meta::enable<meta::neg<meta::is_string_constructible<T>>, is_proxy_primitive<meta::unqualified_t<T>>> = meta::enabler>
|
||||
operator T ( ) const {
|
||||
const Super& super = *static_cast<const Super*>(static_cast<const void*>(this));
|
||||
return super.template get<T>( );
|
||||
}
|
||||
|
||||
template<typename T, meta::EnableIf<meta::Not<meta::is_string_constructible<T>>, meta::Not<is_proxy_primitive<meta::Unqualified<T>>>> = 0>
|
||||
template<typename T, meta::enable<meta::neg<meta::is_string_constructible<T>>, meta::neg<is_proxy_primitive<meta::unqualified_t<T>>>> = meta::enabler>
|
||||
operator T& ( ) const {
|
||||
const Super& super = *static_cast<const Super*>(static_cast<const void*>(this));
|
||||
return super.template get<T&>( );
|
||||
|
@ -30,7 +30,7 @@ namespace detail {
|
||||
struct default_construct {
|
||||
template<typename T, typename... Args>
|
||||
static void construct(T&& obj, Args&&... args) {
|
||||
std::allocator<meta::Unqualified<T>> alloc{};
|
||||
std::allocator<meta::unqualified_t<T>> alloc{};
|
||||
alloc.construct(obj, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ struct default_construct {
|
||||
struct default_destruct {
|
||||
template<typename T>
|
||||
static void destroy(T&& obj) {
|
||||
std::allocator<meta::Unqualified<T>> alloc{};
|
||||
std::allocator<meta::unqualified_t<T>> alloc{};
|
||||
alloc.destroy(obj);
|
||||
}
|
||||
|
||||
|
@ -27,14 +27,14 @@
|
||||
|
||||
namespace sol {
|
||||
namespace detail {
|
||||
template<typename R, typename... Args, typename F, typename = std::result_of_t<meta::Unqualified<F>(Args...)>>
|
||||
inline auto resolve_i(types<R(Args...)>, F&&) -> R(meta::Unqualified<F>::*)(Args...) {
|
||||
template<typename R, typename... Args, typename F, typename = std::result_of_t<meta::unqualified_t<F>(Args...)>>
|
||||
inline auto resolve_i(types<R(Args...)>, F&&) -> R(meta::unqualified_t<F>::*)(Args...) {
|
||||
using Sig = R(Args...);
|
||||
typedef meta::Unqualified<F> Fu;
|
||||
typedef meta::unqualified_t<F> Fu;
|
||||
return static_cast<Sig Fu::*>(&Fu::operator());
|
||||
}
|
||||
|
||||
template<typename F, typename U = meta::Unqualified<F>>
|
||||
template<typename F, typename U = meta::unqualified_t<F>>
|
||||
inline auto resolve_f(std::true_type, F&& f)
|
||||
-> decltype(resolve_i(types<meta::function_signature_t<decltype(&U::operator())>>(), std::forward<F>(f))) {
|
||||
return resolve_i(types<meta::function_signature_t<decltype(&U::operator())>>(), std::forward<F>(f));
|
||||
@ -46,7 +46,7 @@ inline void resolve_f(std::false_type, F&&) {
|
||||
"Cannot use no-template-parameter call with an overloaded functor: specify the signature");
|
||||
}
|
||||
|
||||
template<typename F, typename U = meta::Unqualified<F>>
|
||||
template<typename F, typename U = meta::unqualified_t<F>>
|
||||
inline auto resolve_i(types<>, F&& f) -> decltype(resolve_f(meta::has_deducible_signature<U>(), std::forward<F>(f))) {
|
||||
return resolve_f(meta::has_deducible_signature<U> {}, std::forward<F>(f));
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ struct is_this_state_raw : std::false_type {};
|
||||
template <>
|
||||
struct is_this_state_raw<this_state> : std::true_type {};
|
||||
template <typename T>
|
||||
using is_this_state = is_this_state_raw<meta::Unqualified<T>>;
|
||||
using is_this_state = is_this_state_raw<meta::unqualified_t<T>>;
|
||||
|
||||
template<typename T>
|
||||
inline int push_as_upvalues(lua_State* L, T& item) {
|
||||
@ -75,18 +75,20 @@ inline std::pair<T, int> get_as_upvalues(lua_State* L, int index = 1) {
|
||||
|
||||
template <bool checkargs = default_check_arguments, std::size_t... I, typename R, typename... Args, typename Fx, typename... FxArgs, typename = std::enable_if_t<!std::is_void<R>::value>>
|
||||
inline decltype(auto) call(types<R>, types<Args...> ta, std::index_sequence<I...> tai, lua_State* L, int start, Fx&& fx, FxArgs&&... args) {
|
||||
typedef meta::index_in_pack<this_state, Args...> state_index;
|
||||
typedef meta::index_in_pack<variadic_args, Args...> va_pack_index;
|
||||
check_types<checkargs>{}.check(ta, tai, L, start, type_panic);
|
||||
return fx(std::forward<FxArgs>(args)..., stack_detail::unchecked_get<Args>(L, start + I - static_cast<int>(state_index::value < I) - static_cast<int>(va_pack_index::value < I))...);
|
||||
#ifndef _MSC_VER
|
||||
static_assert(meta::all<meta::is_not_move_only<Args>...>::value, "One of the arguments being bound is a move-only type, and it is not being taken by reference: this will break your code. Please take a reference and std::move it manually if this was your intention.");
|
||||
#endif // This compiler make me so fucking sad
|
||||
check_types<checkargs>{}.check(ta, tai, L, start, type_panic);
|
||||
return fx(std::forward<FxArgs>(args)..., stack_detail::unchecked_get<Args>(L, start + I - meta::count_for_to_pack<I, is_transparent_argument, Args...>::value)...);
|
||||
}
|
||||
|
||||
template <bool checkargs = default_check_arguments, std::size_t... I, typename... Args, typename Fx, typename... FxArgs>
|
||||
inline void call(types<void>, types<Args...> ta, std::index_sequence<I...> tai, lua_State* L, int start, Fx&& fx, FxArgs&&... args) {
|
||||
typedef meta::index_in_pack<this_state, Args...> state_index;
|
||||
typedef meta::index_in_pack<variadic_args, Args...> va_pack_index;
|
||||
#ifndef _MSC_VER
|
||||
static_assert(meta::all<meta::is_not_move_only<Args>...>::value, "One of the arguments being bound is a move-only type, and it is not being taken by reference: this will break your code. Please take a reference and std::move it manually if this was your intention.");
|
||||
#endif // This compiler make me so fucking sad
|
||||
check_types<checkargs>{}.check(ta, tai, L, start, type_panic);
|
||||
fx(std::forward<FxArgs>(args)..., stack_detail::unchecked_get<Args>(L, start + I - static_cast<int>(state_index::value < I) - static_cast<int>(va_pack_index::value < I))...);
|
||||
fx(std::forward<FxArgs>(args)..., stack_detail::unchecked_get<Args>(L, start + I - meta::count_for_to_pack<I, is_transparent_argument, Args...>::value)...);
|
||||
}
|
||||
} // stack_detail
|
||||
|
||||
@ -147,15 +149,15 @@ inline void call_from_top(types<void> tr, types<Args...> ta, lua_State* L, Fx&&
|
||||
template<int additionalpop = 0, bool check_args = stack_detail::default_check_arguments, typename... Args, typename Fx, typename... FxArgs>
|
||||
inline int call_into_lua(types<void> tr, types<Args...> ta, lua_State* L, int start, Fx&& fx, FxArgs&&... fxargs) {
|
||||
call<check_args>(tr, ta, L, start, std::forward<Fx>(fx), std::forward<FxArgs>(fxargs)...);
|
||||
int nargs = static_cast<int>(sizeof...(Args)) + additionalpop - meta::count_if_pack<stack_detail::is_this_state, Args...>::value;
|
||||
int nargs = static_cast<int>(sizeof...(Args)) + additionalpop - meta::count_for_pack<stack_detail::is_this_state, Args...>::value;
|
||||
lua_pop(L, nargs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<int additionalpop = 0, bool check_args = stack_detail::default_check_arguments, typename Ret0, typename... Ret, typename... Args, typename Fx, typename... FxArgs, typename = std::enable_if_t<meta::Not<std::is_void<Ret0>>::value>>
|
||||
template<int additionalpop = 0, bool check_args = stack_detail::default_check_arguments, typename Ret0, typename... Ret, typename... Args, typename Fx, typename... FxArgs, typename = std::enable_if_t<meta::neg<std::is_void<Ret0>>::value>>
|
||||
inline int call_into_lua(types<Ret0, Ret...>, types<Args...> ta, lua_State* L, int start, Fx&& fx, FxArgs&&... fxargs) {
|
||||
decltype(auto) r = call<check_args>(types<meta::return_type_t<Ret0, Ret...>>(), ta, L, start, std::forward<Fx>(fx), std::forward<FxArgs>(fxargs)...);
|
||||
int nargs = static_cast<int>(sizeof...(Args)) + additionalpop - meta::count_if_pack<stack_detail::is_this_state, Args...>::value;
|
||||
int nargs = static_cast<int>(sizeof...(Args)) + additionalpop - meta::count_for_pack<stack_detail::is_this_state, Args...>::value;
|
||||
lua_pop(L, nargs);
|
||||
return push_reference(L, std::forward<decltype(r)>(r));
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ struct check_types {
|
||||
static bool check(types<T, Args...>, std::index_sequence<I0, I...>, lua_State* L, int firstargument, Handler&& handler) {
|
||||
if (!stack::check<T>(L, firstargument + I0, handler))
|
||||
return false;
|
||||
return check(types<Args...>(), std::index_sequence<I...>(), L, firstargument - static_cast<int>(is_transparent_argument<meta::Unqualified<T>>::value), std::forward<Handler>(handler));
|
||||
return check(types<Args...>(), std::index_sequence<I...>(), L, firstargument - static_cast<int>(is_transparent_argument<meta::unqualified_t<T>>::value), std::forward<Handler>(handler));
|
||||
}
|
||||
|
||||
template <typename Handler>
|
||||
@ -257,7 +257,7 @@ struct checker<T, type::userdata, C> {
|
||||
handler(L, index, type::userdata, indextype);
|
||||
return false;
|
||||
}
|
||||
if (meta::Or<std::is_same<T, light_userdata_value>, std::is_same<T, userdata_value>, std::is_same<T, userdata>, std::is_same<T, lightuserdata>>::value)
|
||||
if (meta::any<std::is_same<T, light_userdata_value>, std::is_same<T, userdata_value>, std::is_same<T, userdata>, std::is_same<T, lightuserdata>>::value)
|
||||
return true;
|
||||
if (lua_getmetatable(L, index) == 0) {
|
||||
return true;
|
||||
|
@ -51,7 +51,7 @@ struct check_getter<optional<T>> {
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct check_getter<T, std::enable_if_t<std::is_integral<T>::value && !lua_type_of<T>::value == type::number>> {
|
||||
struct check_getter<T, std::enable_if_t<std::is_integral<T>::value && lua_type_of<T>::value == type::number>> {
|
||||
template <typename Handler>
|
||||
static optional<T> get( lua_State* L, int index, Handler&& handler) {
|
||||
int isnum = 0;
|
||||
|
@ -104,7 +104,7 @@ false;
|
||||
#endif
|
||||
template<typename T>
|
||||
inline decltype(auto) unchecked_get(lua_State* L, int index = -1) {
|
||||
return getter<meta::Unqualified<T>>{}.get(L, index);
|
||||
return getter<meta::unqualified_t<T>>{}.get(L, index);
|
||||
}
|
||||
} // stack_detail
|
||||
|
||||
@ -115,23 +115,23 @@ inline bool maybe_indexable(lua_State* L, int index = -1) {
|
||||
|
||||
template<typename T, typename... Args>
|
||||
inline int push(lua_State* L, T&& t, Args&&... args) {
|
||||
return pusher<meta::Unqualified<T>>{}.push(L, std::forward<T>(t), std::forward<Args>(args)...);
|
||||
return pusher<meta::unqualified_t<T>>{}.push(L, std::forward<T>(t), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
// overload allows to use a pusher of a specific type, but pass in any kind of args
|
||||
template<typename T, typename Arg, typename... Args>
|
||||
inline int push(lua_State* L, Arg&& arg, Args&&... args) {
|
||||
return pusher<meta::Unqualified<T>>{}.push(L, std::forward<Arg>(arg), std::forward<Args>(args)...);
|
||||
return pusher<meta::unqualified_t<T>>{}.push(L, std::forward<Arg>(arg), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
inline int push_reference(lua_State* L, T&& t, Args&&... args) {
|
||||
typedef meta::And<
|
||||
typedef meta::all<
|
||||
std::is_lvalue_reference<T>,
|
||||
meta::Not<std::is_const<T>>,
|
||||
meta::Not<is_lua_primitive<T>>
|
||||
meta::neg<std::is_const<T>>,
|
||||
meta::neg<is_lua_primitive<T>>
|
||||
> use_reference_tag;
|
||||
return pusher<std::conditional_t<use_reference_tag::value, detail::as_reference_tag, meta::Unqualified<T>>>{}.push(L, std::forward<T>(t), std::forward<Args>(args)...);
|
||||
return pusher<std::conditional_t<use_reference_tag::value, detail::as_reference_tag, meta::unqualified_t<T>>>{}.push(L, std::forward<T>(t), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
inline int multi_push(lua_State*) {
|
||||
@ -160,7 +160,7 @@ inline int multi_push_reference(lua_State* L, T&& t, Args&&... args) {
|
||||
|
||||
template <typename T, typename Handler>
|
||||
bool check(lua_State* L, int index, Handler&& handler) {
|
||||
typedef meta::Unqualified<T> Tu;
|
||||
typedef meta::unqualified_t<T> Tu;
|
||||
checker<Tu> c;
|
||||
// VC++ has a bad warning here: shut it up
|
||||
(void)c;
|
||||
@ -175,7 +175,7 @@ bool check(lua_State* L, int index = -1) {
|
||||
|
||||
template<typename T, typename Handler>
|
||||
inline decltype(auto) check_get(lua_State* L, int index, Handler&& handler) {
|
||||
return check_getter<meta::Unqualified<T>>{}.get(L, index, std::forward<Handler>(handler));
|
||||
return check_getter<meta::unqualified_t<T>>{}.get(L, index, std::forward<Handler>(handler));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@ -190,7 +190,7 @@ template <typename T>
|
||||
inline decltype(auto) tagged_get(types<T>, lua_State* L, int index = -1) {
|
||||
#ifdef SOL_CHECK_ARGUMENTS
|
||||
auto op = check_get<T>(L, index, type_panic);
|
||||
typedef typename meta::Unqualified<decltype(op)>::value_type U;
|
||||
typedef typename meta::unqualified_t<decltype(op)>::value_type U;
|
||||
return static_cast<U>(*op);
|
||||
#else
|
||||
return stack_detail::unchecked_get<T>(L, index);
|
||||
@ -211,37 +211,37 @@ inline decltype(auto) get(lua_State* L, int index = -1) {
|
||||
|
||||
template<typename T>
|
||||
inline decltype(auto) pop(lua_State* L) {
|
||||
return popper<meta::Unqualified<T>>{}.pop(L);
|
||||
return popper<meta::unqualified_t<T>>{}.pop(L);
|
||||
}
|
||||
|
||||
template <bool global = false, typename Key>
|
||||
void get_field(lua_State* L, Key&& key) {
|
||||
field_getter<meta::Unqualified<Key>, global>{}.get(L, std::forward<Key>(key));
|
||||
field_getter<meta::unqualified_t<Key>, global>{}.get(L, std::forward<Key>(key));
|
||||
}
|
||||
|
||||
template <bool global = false, typename Key>
|
||||
void get_field(lua_State* L, Key&& key, int tableindex) {
|
||||
field_getter<meta::Unqualified<Key>, global>{}.get(L, std::forward<Key>(key), tableindex);
|
||||
field_getter<meta::unqualified_t<Key>, global>{}.get(L, std::forward<Key>(key), tableindex);
|
||||
}
|
||||
|
||||
template <bool global = false, typename Key>
|
||||
probe probe_get_field(lua_State* L, Key&& key) {
|
||||
return probe_field_getter<meta::Unqualified<Key>, global>{}.get(L, std::forward<Key>(key));
|
||||
return probe_field_getter<meta::unqualified_t<Key>, global>{}.get(L, std::forward<Key>(key));
|
||||
}
|
||||
|
||||
template <bool global = false, typename Key>
|
||||
probe probe_get_field(lua_State* L, Key&& key, int tableindex) {
|
||||
return probe_field_getter<meta::Unqualified<Key>, global>{}.get(L, std::forward<Key>(key), tableindex);
|
||||
return probe_field_getter<meta::unqualified_t<Key>, global>{}.get(L, std::forward<Key>(key), tableindex);
|
||||
}
|
||||
|
||||
template <bool global = false, typename Key, typename Value>
|
||||
void set_field(lua_State* L, Key&& key, Value&& value) {
|
||||
field_setter<meta::Unqualified<Key>, global>{}.set(L, std::forward<Key>(key), std::forward<Value>(value));
|
||||
field_setter<meta::unqualified_t<Key>, global>{}.set(L, std::forward<Key>(key), std::forward<Value>(value));
|
||||
}
|
||||
|
||||
template <bool global = false, typename Key, typename Value>
|
||||
void set_field(lua_State* L, Key&& key, Value&& value, int tableindex) {
|
||||
field_setter<meta::Unqualified<Key>, global>{}.set(L, std::forward<Key>(key), std::forward<Value>(value), tableindex);
|
||||
field_setter<meta::unqualified_t<Key>, global>{}.set(L, std::forward<Key>(key), std::forward<Value>(value), tableindex);
|
||||
}
|
||||
} // stack
|
||||
} // sol
|
||||
|
@ -30,7 +30,6 @@
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <codecvt>
|
||||
|
||||
namespace sol {
|
||||
namespace stack {
|
||||
@ -50,14 +49,14 @@ struct getter<T, std::enable_if_t<std::is_floating_point<T>::value>> {
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct getter<T, std::enable_if_t<meta::And<std::is_integral<T>, std::is_signed<T>>::value>> {
|
||||
struct getter<T, std::enable_if_t<meta::all<std::is_integral<T>, std::is_signed<T>>::value>> {
|
||||
static T get(lua_State* L, int index = -1) {
|
||||
return static_cast<T>(lua_tointeger(L, index));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct getter<T, std::enable_if_t<meta::And<std::is_integral<T>, std::is_unsigned<T>>::value>> {
|
||||
struct getter<T, std::enable_if_t<meta::all<std::is_integral<T>, std::is_unsigned<T>>::value>> {
|
||||
static T get(lua_State* L, int index = -1) {
|
||||
return static_cast<T>(lua_tointeger(L, index));
|
||||
}
|
||||
@ -123,52 +122,26 @@ struct getter<char> {
|
||||
}
|
||||
};
|
||||
|
||||
#if 0
|
||||
|
||||
template<>
|
||||
struct getter<std::wstring> {
|
||||
static std::wstring get(lua_State* L, int index = -1) {
|
||||
size_t len;
|
||||
auto str = lua_tolstring(L, index, &len);
|
||||
typedef std::codecvt_utf8<wchar_t> convert;
|
||||
std::wstring_convert<convert, wchar_t> conv;
|
||||
return conv.from_bytes(str, str + len);
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct getter<std::u16string> {
|
||||
static std::u16string get(lua_State* L, int index = -1) {
|
||||
size_t len;
|
||||
auto str = lua_tolstring(L, index, &len);
|
||||
#ifdef _MSC_VER // https://connect.microsoft.com/VisualStudio/feedback/details/1348277/link-error-when-using-std-codecvt-utf8-utf16-char16-t
|
||||
typedef uint16_t T;
|
||||
typedef std::codecvt_utf8<T> convert;
|
||||
std::wstring_convert<convert, T> conv;
|
||||
std::basic_string<T> shitty = conv.from_bytes(str, str + len);
|
||||
return std::u16string(shitty.cbegin(), shitty.cend()); // fuck you VC++
|
||||
#else
|
||||
typedef std::codecvt_utf8<char16_t> convert;
|
||||
std::wstring_convert<convert, char16_t> conv;
|
||||
return conv.from_bytes(str, str + len);
|
||||
#endif // VC++
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct getter<std::u32string> {
|
||||
static std::u32string get(lua_State* L, int index = -1) {
|
||||
size_t len;
|
||||
auto str = lua_tolstring(L, index, &len);
|
||||
#ifdef _MSC_VER // https://connect.microsoft.com/VisualStudio/feedback/details/1348277/link-error-when-using-std-codecvt-utf8-utf16-char16-t
|
||||
typedef int32_t T;
|
||||
typedef std::codecvt_utf8<T> convert;
|
||||
std::wstring_convert<convert, T> conv;
|
||||
std::basic_string<T> shitty = conv.from_bytes(str, str + len);
|
||||
return std::u32string(shitty.cbegin(), shitty.cend()); // fuck you VC++
|
||||
#else
|
||||
typedef std::codecvt_utf8<char32_t> convert;
|
||||
std::wstring_convert<convert, char32_t> conv;
|
||||
return conv.from_bytes(str, str + len);
|
||||
#endif // VC++
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
@ -196,6 +169,8 @@ struct getter<char32_t> {
|
||||
}
|
||||
};
|
||||
|
||||
#endif // For a distant future
|
||||
|
||||
template<>
|
||||
struct getter<nil_t> {
|
||||
static nil_t get(lua_State*, int = -1) {
|
||||
|
@ -57,8 +57,8 @@ struct popper<std::pair<A, B>> {
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct popper<T, std::enable_if_t<std::is_base_of<stack_reference, meta::Unqualified<T>>::value>> {
|
||||
static_assert(meta::Not<std::is_base_of<stack_reference, meta::Unqualified<T>>>::value, "You cannot pop something that derives from stack_reference: it will not remain on the stack and thusly will go out of scope!");
|
||||
struct popper<T, std::enable_if_t<std::is_base_of<stack_reference, meta::unqualified_t<T>>::value>> {
|
||||
static_assert(meta::neg<std::is_base_of<stack_reference, meta::unqualified_t<T>>>::value, "You cannot pop something that derives from stack_reference: it will not remain on the stack and thusly will go out of scope!");
|
||||
};
|
||||
} // stack
|
||||
} // sol
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "raii.hpp"
|
||||
#include "optional.hpp"
|
||||
#include <memory>
|
||||
#include <codecvt>
|
||||
|
||||
namespace sol {
|
||||
namespace stack {
|
||||
@ -77,7 +76,7 @@ struct pusher<T, std::enable_if_t<is_unique_usertype<T>::value>> {
|
||||
typedef typename unique_usertype_traits<T>::type P;
|
||||
typedef typename unique_usertype_traits<T>::actual_type Real;
|
||||
|
||||
template <typename Arg, meta::EnableIf<std::is_base_of<Real, meta::Unqualified<Arg>>> = 0>
|
||||
template <typename Arg, meta::enable<std::is_base_of<Real, meta::unqualified_t<Arg>>> = meta::enabler>
|
||||
static int push(lua_State* L, Arg&& arg) {
|
||||
if (unique_usertype_traits<T>::is_null(arg))
|
||||
return stack::push(L, nil);
|
||||
@ -121,7 +120,7 @@ struct pusher<T, std::enable_if_t<std::is_floating_point<T>::value>> {
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct pusher<T, std::enable_if_t<meta::And<std::is_integral<T>, std::is_signed<T>>::value>> {
|
||||
struct pusher<T, std::enable_if_t<meta::all<std::is_integral<T>, std::is_signed<T>>::value>> {
|
||||
static int push(lua_State* L, const T& value) {
|
||||
lua_pushinteger(L, static_cast<lua_Integer>(value));
|
||||
return 1;
|
||||
@ -129,7 +128,7 @@ struct pusher<T, std::enable_if_t<meta::And<std::is_integral<T>, std::is_signed<
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct pusher<T, std::enable_if_t<meta::And<std::is_integral<T>, std::is_unsigned<T>>::value>> {
|
||||
struct pusher<T, std::enable_if_t<meta::all<std::is_integral<T>, std::is_unsigned<T>>::value>> {
|
||||
static int push(lua_State* L, const T& value) {
|
||||
typedef std::make_signed_t<T> signed_int;
|
||||
return stack::push(L, static_cast<signed_int>(value));
|
||||
@ -137,7 +136,7 @@ struct pusher<T, std::enable_if_t<meta::And<std::is_integral<T>, std::is_unsigne
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct pusher<T, std::enable_if_t<meta::And<meta::has_begin_end<T>, meta::Not<meta::has_key_value_pair<T>>, meta::Not<std::is_base_of<reference, T>>>::value>> {
|
||||
struct pusher<T, std::enable_if_t<meta::all<meta::has_begin_end<T>, meta::neg<meta::has_key_value_pair<T>>, meta::neg<std::is_base_of<reference, T>>>::value>> {
|
||||
static int push(lua_State* L, const T& cont) {
|
||||
lua_createtable(L, static_cast<int>(cont.size()), 0);
|
||||
int tableindex = lua_gettop(L);
|
||||
@ -150,7 +149,7 @@ struct pusher<T, std::enable_if_t<meta::And<meta::has_begin_end<T>, meta::Not<me
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct pusher<T, std::enable_if_t<meta::And<meta::has_begin_end<T>, meta::has_key_value_pair<T>, meta::Not<std::is_base_of<reference, T>>>::value>> {
|
||||
struct pusher<T, std::enable_if_t<meta::all<meta::has_begin_end<T>, meta::has_key_value_pair<T>, meta::neg<std::is_base_of<reference, T>>>::value>> {
|
||||
static int push(lua_State* L, const T& cont) {
|
||||
lua_createtable(L, static_cast<int>(cont.size()), 0);
|
||||
int tableindex = lua_gettop(L);
|
||||
@ -253,55 +252,6 @@ struct pusher<const char*> {
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pusher<const wchar_t*> {
|
||||
static int push(lua_State* L, const wchar_t* wstr) {
|
||||
return push(L, wstr, wstr + std::char_traits<wchar_t>::length(wstr));
|
||||
}
|
||||
static int push(lua_State* L, const wchar_t* wstrb, const wchar_t* wstre) {
|
||||
typedef std::codecvt_utf8<wchar_t> convert;
|
||||
std::wstring_convert<convert, wchar_t> conv;
|
||||
std::string str = conv.to_bytes( wstrb, wstre );
|
||||
return stack::push(L, str);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pusher<const char16_t*> {
|
||||
static int push(lua_State* L, const char16_t* u16str) {
|
||||
return push(L, u16str, u16str + std::char_traits<char16_t>::length(u16str));
|
||||
}
|
||||
static int push(lua_State* L, const char16_t* u16strb, const char16_t* u16stre) {
|
||||
#ifdef _MSC_VER // https://connect.microsoft.com/VisualStudio/feedback/details/1348277/link-error-when-using-std-codecvt-utf8-utf16-char16-t
|
||||
typedef uint16_t T;
|
||||
#else
|
||||
typedef char16_t T;
|
||||
#endif // VC++
|
||||
typedef std::codecvt_utf8<T> convert;
|
||||
std::wstring_convert<convert, T> conv;
|
||||
std::string str = conv.to_bytes( reinterpret_cast<const T*>(u16strb), reinterpret_cast<const T*>(u16stre) );
|
||||
return stack::push(L, str);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pusher<const char32_t*> {
|
||||
static int push(lua_State* L, const char32_t* u32str) {
|
||||
return push(L, u32str, u32str + std::char_traits<char32_t>::length(u32str));
|
||||
}
|
||||
static int push(lua_State* L, const char32_t* u32strb, const char32_t* u32stre) {
|
||||
#ifdef _MSC_VER // https://connect.microsoft.com/VisualStudio/feedback/details/1348277/link-error-when-using-std-codecvt-utf8-utf16-char16-t
|
||||
typedef uint32_t T;
|
||||
#else
|
||||
typedef char32_t T;
|
||||
#endif // VC++
|
||||
typedef std::codecvt_utf8<T> convert;
|
||||
std::wstring_convert<convert, T> conv;
|
||||
std::string str = conv.to_bytes( reinterpret_cast<const T*>(u32strb), reinterpret_cast<const T*>(u32stre) );
|
||||
return stack::push(L, str);
|
||||
}
|
||||
};
|
||||
|
||||
template<size_t N>
|
||||
struct pusher<char[N]> {
|
||||
static int push(lua_State* L, const char (&str)[N]) {
|
||||
@ -310,27 +260,6 @@ struct pusher<char[N]> {
|
||||
}
|
||||
};
|
||||
|
||||
template<size_t N>
|
||||
struct pusher<wchar_t[N]> {
|
||||
static int push(lua_State* L, const wchar_t (&str)[N]) {
|
||||
return stack::push<const wchar_t*>(L, str, str + N - 1);
|
||||
}
|
||||
};
|
||||
|
||||
template<size_t N>
|
||||
struct pusher<char16_t[N]> {
|
||||
static int push(lua_State* L, const char16_t (&str)[N]) {
|
||||
return stack::push<const char16_t*>(L, str, str + N - 1);
|
||||
}
|
||||
};
|
||||
|
||||
template<size_t N>
|
||||
struct pusher<char32_t[N]> {
|
||||
static int push(lua_State* L, const char32_t (&str)[N]) {
|
||||
return stack::push<const char32_t*>(L, str, str + N - 1);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<char> {
|
||||
static int push(lua_State* L, char c) {
|
||||
@ -339,30 +268,6 @@ struct pusher<char> {
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<wchar_t> {
|
||||
static int push(lua_State* L, wchar_t c) {
|
||||
const wchar_t str[2] = { c, '\0'};
|
||||
return stack::push(L, str);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<char16_t> {
|
||||
static int push(lua_State* L, char16_t c) {
|
||||
const char16_t str[2] = { c, '\0'};
|
||||
return stack::push(L, str);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<char32_t> {
|
||||
static int push(lua_State* L, char32_t c) {
|
||||
const char32_t str[2] = { c, '\0'};
|
||||
return stack::push(L, str);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pusher<std::string> {
|
||||
static int push(lua_State* L, const std::string& str) {
|
||||
@ -371,27 +276,111 @@ struct pusher<std::string> {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
template<>
|
||||
struct pusher<const wchar_t*> {
|
||||
static int push(lua_State* L, const wchar_t* wstr) {
|
||||
return push(L, wstr, wstr + std::char_traits<wchar_t>::length(wstr));
|
||||
}
|
||||
static int push(lua_State* L, const wchar_t* wstrb, const wchar_t* wstre) {
|
||||
std::string str{};
|
||||
return stack::push(L, str);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pusher<const char16_t*> {
|
||||
static int push(lua_State* L, const char16_t* u16str) {
|
||||
return push(L, u16str, u16str + std::char_traits<char16_t>::length(u16str));
|
||||
}
|
||||
static int push(lua_State* L, const char16_t* u16strb, const char16_t* u16stre) {
|
||||
std::string str{};
|
||||
return stack::push(L, str);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pusher<const char32_t*> {
|
||||
static int push(lua_State* L, const char32_t* u32str) {
|
||||
return push(L, u32str, u32str + std::char_traits<char32_t>::length(u32str));
|
||||
}
|
||||
static int push(lua_State* L, const char32_t* u32strb, const char32_t* u32stre) {
|
||||
std::string str{};
|
||||
return stack::push(L, str);
|
||||
}
|
||||
};
|
||||
|
||||
template<size_t N>
|
||||
struct pusher<wchar_t[N]> {
|
||||
static int push(lua_State* L, const wchar_t(&str)[N]) {
|
||||
return stack::push<const wchar_t*>(L, str, str + N - 1);
|
||||
}
|
||||
};
|
||||
|
||||
template<size_t N>
|
||||
struct pusher<char16_t[N]> {
|
||||
static int push(lua_State* L, const char16_t(&str)[N]) {
|
||||
return stack::push<const char16_t*>(L, str, str + N - 1);
|
||||
}
|
||||
};
|
||||
|
||||
template<size_t N>
|
||||
struct pusher<char32_t[N]> {
|
||||
static int push(lua_State* L, const char32_t(&str)[N]) {
|
||||
return stack::push<const char32_t*>(L, str, str + N - 1);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<wchar_t> {
|
||||
static int push(lua_State* L, wchar_t c) {
|
||||
const wchar_t str[2] = { c, '\0' };
|
||||
return stack::push(L, str);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<char16_t> {
|
||||
static int push(lua_State* L, char16_t c) {
|
||||
const char16_t str[2] = { c, '\0' };
|
||||
return stack::push(L, str);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<char32_t> {
|
||||
static int push(lua_State* L, char32_t c) {
|
||||
const char32_t str[2] = { c, '\0' };
|
||||
return stack::push(L, str);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pusher<std::wstring> {
|
||||
static int push(lua_State* L, const std::wstring& wstr) {
|
||||
return stack::push(L, wstr.data(), wstr.data() + wstr.size());
|
||||
}
|
||||
static int push(lua_State* L, const std::wstring& wstr) {
|
||||
return stack::push(L, wstr.data(), wstr.data() + wstr.size());
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pusher<std::u16string> {
|
||||
static int push(lua_State* L, const std::u16string& u16str) {
|
||||
return stack::push(L, u16str.data(), u16str.data() + u16str.size());
|
||||
}
|
||||
static int push(lua_State* L, const std::u16string& u16str) {
|
||||
return stack::push(L, u16str.data(), u16str.data() + u16str.size());
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pusher<std::u32string> {
|
||||
static int push(lua_State* L, const std::u32string& u32str) {
|
||||
return stack::push(L, u32str.data(), u32str.data() + u32str.size());
|
||||
}
|
||||
static int push(lua_State* L, const std::u32string& u32str) {
|
||||
return stack::push(L, u32str.data(), u32str.data() + u32str.size());
|
||||
}
|
||||
};
|
||||
|
||||
#endif // Bad conversions
|
||||
|
||||
template<typename... Args>
|
||||
struct pusher<std::tuple<Args...>> {
|
||||
template <std::size_t... I, typename T>
|
||||
|
333
sol/stack_push.hpp~RF9798847.TMP
Normal file
333
sol/stack_push.hpp~RF9798847.TMP
Normal file
@ -0,0 +1,333 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013-2016 Rapptz, ThePhD and contributors
|
||||
|
||||
// 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_STACK_PUSH_HPP
|
||||
#define SOL_STACK_PUSH_HPP
|
||||
|
||||
#include "stack_core.hpp"
|
||||
#include "raii.hpp"
|
||||
#include "optional.hpp"
|
||||
#include <memory>
|
||||
|
||||
namespace sol {
|
||||
namespace stack {
|
||||
template<typename T, typename>
|
||||
struct pusher {
|
||||
template <typename... Args>
|
||||
static int push(lua_State* L, Args&&... args) {
|
||||
// Basically, we store all user-data like this:
|
||||
// If it's a movable/copyable value (no std::ref(x)), then we store the pointer to the new
|
||||
// data in the first sizeof(T*) bytes, and then however many bytes it takes to
|
||||
// do the actual object. Things that are std::ref or plain T* are stored as
|
||||
// just the sizeof(T*), and nothing else.
|
||||
T** pointerpointer = static_cast<T**>(lua_newuserdata(L, sizeof(T*) + sizeof(T)));
|
||||
T*& referencereference = *pointerpointer;
|
||||
T* allocationtarget = reinterpret_cast<T*>(pointerpointer + 1);
|
||||
referencereference = allocationtarget;
|
||||
std::allocator<T> alloc{};
|
||||
alloc.construct(allocationtarget, std::forward<Args>(args)...);
|
||||
luaL_newmetatable(L, &usertype_traits<T>::metatable[0]);
|
||||
lua_setmetatable(L, -2);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<detail::as_reference_tag> {
|
||||
template <typename T>
|
||||
static int push(lua_State* L, T&& obj) {
|
||||
return stack::push(L, detail::ptr(obj));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct pusher<T*> {
|
||||
static int push(lua_State* L, T* obj) {
|
||||
if (obj == nullptr)
|
||||
return stack::push(L, nil);
|
||||
T** pref = static_cast<T**>(lua_newuserdata(L, sizeof(T*)));
|
||||
*pref = obj;
|
||||
luaL_getmetatable(L, &usertype_traits<T*>::metatable[0]);
|
||||
lua_setmetatable(L, -2);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct pusher<T, std::enable_if_t<is_unique_usertype<T>::value>> {
|
||||
typedef typename unique_usertype_traits<T>::type P;
|
||||
typedef typename unique_usertype_traits<T>::actual_type Real;
|
||||
|
||||
template <typename Arg, meta::EnableIf<std::is_base_of<Real, meta::Unqualified<Arg>>> = 0>
|
||||
static int push(lua_State* L, Arg&& arg) {
|
||||
if (unique_usertype_traits<T>::is_null(arg))
|
||||
return stack::push(L, nil);
|
||||
return push_deep(L, std::forward<Arg>(arg));
|
||||
}
|
||||
|
||||
template <typename Arg0, typename Arg1, typename... Args>
|
||||
static int push(lua_State* L, Arg0&& arg0, Arg0&& arg1, Args&&... args) {
|
||||
return push_deep(L, std::forward<Arg0>(arg0), std::forward<Arg1>(arg1), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
static int push_deep(lua_State* L, Args&&... args) {
|
||||
P** pref = static_cast<P**>(lua_newuserdata(L, sizeof(P*) + sizeof(detail::special_destruct_func) + sizeof(Real)));
|
||||
detail::special_destruct_func* fx = static_cast<detail::special_destruct_func*>(static_cast<void*>(pref + 1));
|
||||
Real* mem = static_cast<Real*>(static_cast<void*>(fx + 1));
|
||||
*fx = detail::special_destruct<P, Real>;
|
||||
detail::default_construct::construct(mem, std::forward<Args>(args)...);
|
||||
*pref = unique_usertype_traits<T>::get(*mem);
|
||||
if (luaL_newmetatable(L, &usertype_traits<detail::unique_usertype<P>>::metatable[0]) == 1) {
|
||||
set_field(L, "__gc", detail::unique_destruct<P>);
|
||||
}
|
||||
lua_setmetatable(L, -2);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct pusher<std::reference_wrapper<T>> {
|
||||
static int push(lua_State* L, const std::reference_wrapper<T>& t) {
|
||||
return stack::push(L, std::addressof(detail::deref(t.get())));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct pusher<T, std::enable_if_t<std::is_floating_point<T>::value>> {
|
||||
static int push(lua_State* L, const T& value) {
|
||||
lua_pushnumber(L, value);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct pusher<T, std::enable_if_t<meta::And<std::is_integral<T>, std::is_signed<T>>::value>> {
|
||||
static int push(lua_State* L, const T& value) {
|
||||
lua_pushinteger(L, static_cast<lua_Integer>(value));
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct pusher<T, std::enable_if_t<meta::And<std::is_integral<T>, std::is_unsigned<T>>::value>> {
|
||||
static int push(lua_State* L, const T& value) {
|
||||
typedef std::make_signed_t<T> signed_int;
|
||||
return stack::push(L, static_cast<signed_int>(value));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct pusher<T, std::enable_if_t<meta::And<meta::has_begin_end<T>, meta::Not<meta::has_key_value_pair<T>>, meta::Not<std::is_base_of<reference, T>>>::value>> {
|
||||
static int push(lua_State* L, const T& cont) {
|
||||
lua_createtable(L, static_cast<int>(cont.size()), 0);
|
||||
int tableindex = lua_gettop(L);
|
||||
unsigned index = 1;
|
||||
for(auto&& i : cont) {
|
||||
set_field(L, index++, i, tableindex);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct pusher<T, std::enable_if_t<meta::And<meta::has_begin_end<T>, meta::has_key_value_pair<T>, meta::Not<std::is_base_of<reference, T>>>::value>> {
|
||||
static int push(lua_State* L, const T& cont) {
|
||||
lua_createtable(L, static_cast<int>(cont.size()), 0);
|
||||
int tableindex = lua_gettop(L);
|
||||
for(auto&& pair : cont) {
|
||||
set_field(L, pair.first, pair.second, tableindex);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct pusher<T, std::enable_if_t<std::is_base_of<reference, T>::value || std::is_base_of<stack_reference, T>::value>> {
|
||||
static int push(lua_State*, T& ref) {
|
||||
return ref.push();
|
||||
}
|
||||
|
||||
static int push(lua_State*, T&& ref) {
|
||||
return ref.push();
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pusher<bool> {
|
||||
static int push(lua_State* L, bool b) {
|
||||
lua_pushboolean(L, b);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pusher<nil_t> {
|
||||
static int push(lua_State* L, nil_t) {
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pusher<metatable_key_t> {
|
||||
static int push(lua_State* L, metatable_key_t) {
|
||||
lua_pushlstring(L, "__mt", 4);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pusher<std::remove_pointer_t<lua_CFunction>> {
|
||||
static int push(lua_State* L, lua_CFunction func, int n = 0) {
|
||||
lua_pushcclosure(L, func, n);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pusher<lua_CFunction> {
|
||||
static int push(lua_State* L, lua_CFunction func, int n = 0) {
|
||||
lua_pushcclosure(L, func, n);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pusher<c_closure> {
|
||||
static int push(lua_State* L, c_closure closure) {
|
||||
lua_pushcclosure(L, closure.c_function, closure.upvalues);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pusher<void*> {
|
||||
static int push(lua_State* L, void* userdata) {
|
||||
lua_pushlightuserdata(L, userdata);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pusher<light_userdata_value> {
|
||||
static int push(lua_State* L, light_userdata_value userdata) {
|
||||
lua_pushlightuserdata(L, userdata);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pusher<userdata_value> {
|
||||
static int push(lua_State* L, userdata_value data) {
|
||||
void** ud = static_cast<void**>(lua_newuserdata(L, sizeof(void*)));
|
||||
*ud = data.value;
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pusher<const char*> {
|
||||
static int push(lua_State* L, const char* str) {
|
||||
lua_pushlstring(L, str, std::char_traits<char>::length(str));
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template<size_t N>
|
||||
struct pusher<char[N]> {
|
||||
static int push(lua_State* L, const char (&str)[N]) {
|
||||
lua_pushlstring(L, str, N - 1);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<char> {
|
||||
static int push(lua_State* L, char c) {
|
||||
const char str[2] = { c, '\0'};
|
||||
return stack::push(L, str);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pusher<std::string> {
|
||||
static int push(lua_State* L, const std::string& str) {
|
||||
lua_pushlstring(L, str.c_str(), str.size());
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename... Args>
|
||||
struct pusher<std::tuple<Args...>> {
|
||||
template <std::size_t... I, typename T>
|
||||
static int push(std::index_sequence<I...>, lua_State* L, T&& t) {
|
||||
int pushcount = 0;
|
||||
(void)detail::swallow{ 0, (pushcount += stack::push(L,
|
||||
detail::forward_get<I>(t)
|
||||
), 0)... };
|
||||
return pushcount;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static int push(lua_State* L, T&& t) {
|
||||
return push(std::index_sequence_for<Args...>(), L, std::forward<T>(t));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename A, typename B>
|
||||
struct pusher<std::pair<A, B>> {
|
||||
template <typename T>
|
||||
static int push(lua_State* L, T&& t) {
|
||||
int pushcount = stack::push(L, detail::forward_get<0>(t));
|
||||
pushcount += stack::push(L, detail::forward_get<1>(t));
|
||||
return pushcount;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename O>
|
||||
struct pusher<optional<O>> {
|
||||
template <typename T>
|
||||
static int push(lua_State* L, T&& t) {
|
||||
if (t == nullopt) {
|
||||
return stack::push(L, nullopt);
|
||||
}
|
||||
return stack::push(L, t.value());
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pusher<nullopt_t> {
|
||||
static int push(lua_State* L, nullopt_t) {
|
||||
return stack::push(L, nil);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct pusher<this_state> {
|
||||
static int push(lua_State*, const this_state&) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
} // stack
|
||||
} // sol
|
||||
|
||||
#endif // SOL_STACK_PUSH_HPP
|
@ -41,7 +41,7 @@ class basic_table_core : public base_t {
|
||||
friend class state_view;
|
||||
|
||||
template <typename... Args>
|
||||
using is_global = meta::And<meta::Bool<top_level>, meta::is_c_str<Args>...>;
|
||||
using is_global = meta::all<meta::boolean<top_level>, meta::is_c_str<Args>...>;
|
||||
|
||||
template<typename Fx>
|
||||
void for_each(std::true_type, Fx&& fx) const {
|
||||
@ -73,15 +73,15 @@ class basic_table_core : public base_t {
|
||||
-> decltype(stack::pop<std::tuple<Ret0, Ret1, Ret...>>(nullptr)){
|
||||
typedef decltype(stack::pop<std::tuple<Ret0, Ret1, Ret...>>(nullptr)) Tup;
|
||||
return Tup(
|
||||
traverse_get_optional<top_level, Ret0>(meta::is_specialization_of<sol::optional, meta::Unqualified<Ret0>>(), detail::forward_get<0>(keys)),
|
||||
traverse_get_optional<top_level, Ret1>(meta::is_specialization_of<sol::optional, meta::Unqualified<Ret1>>(), detail::forward_get<1>(keys)),
|
||||
traverse_get_optional<top_level, Ret>(meta::is_specialization_of<sol::optional, meta::Unqualified<Ret>>(), detail::forward_get<I>(keys))...
|
||||
traverse_get_optional<top_level, Ret0>(meta::is_specialization_of<sol::optional, meta::unqualified_t<Ret0>>(), detail::forward_get<0>(keys)),
|
||||
traverse_get_optional<top_level, Ret1>(meta::is_specialization_of<sol::optional, meta::unqualified_t<Ret1>>(), detail::forward_get<1>(keys)),
|
||||
traverse_get_optional<top_level, Ret>(meta::is_specialization_of<sol::optional, meta::unqualified_t<Ret>>(), detail::forward_get<I>(keys))...
|
||||
);
|
||||
}
|
||||
|
||||
template<typename Ret, std::size_t I, typename Keys>
|
||||
decltype(auto) tuple_get( types<Ret>, std::index_sequence<I>, Keys&& keys ) const {
|
||||
return traverse_get_optional<top_level, Ret>( meta::is_specialization_of<sol::optional, meta::Unqualified<Ret>>(), detail::forward_get<I>(keys) );
|
||||
return traverse_get_optional<top_level, Ret>( meta::is_specialization_of<sol::optional, meta::unqualified_t<Ret>>(), detail::forward_get<I>(keys) );
|
||||
}
|
||||
|
||||
template<typename Pairs, std::size_t... I>
|
||||
@ -156,7 +156,7 @@ public:
|
||||
typedef iterator const_iterator;
|
||||
|
||||
basic_table_core( ) noexcept : base_t( ) { }
|
||||
template <typename T, meta::EnableIf<meta::Bool<!top_level>, meta::Not<std::is_same<meta::Unqualified<T>, basic_table_core>>, std::is_same<meta::Unqualified<T>, global_table>> = 0>
|
||||
template <typename T, meta::enable<meta::boolean<!top_level>, meta::neg<std::is_same<meta::unqualified_t<T>, basic_table_core>>, std::is_same<meta::unqualified_t<T>, global_table>> = meta::enabler>
|
||||
basic_table_core( T&& r ) noexcept : base_t( std::forward<T>(r) ) { }
|
||||
basic_table_core(const basic_table_core&) = default;
|
||||
basic_table_core(basic_table_core&&) = default;
|
||||
@ -215,7 +215,7 @@ public:
|
||||
template <typename T, typename... Keys>
|
||||
decltype(auto) traverse_get( Keys&&... keys ) const {
|
||||
auto pp = stack::push_pop<is_global<Keys...>::value>(*this);
|
||||
return traverse_get_optional<top_level, T>(meta::is_specialization_of<sol::optional, meta::Unqualified<T>>(), std::forward<Keys>(keys)...);
|
||||
return traverse_get_optional<top_level, T>(meta::is_specialization_of<sol::optional, meta::unqualified_t<T>>(), std::forward<Keys>(keys)...);
|
||||
}
|
||||
|
||||
template <typename... Keys>
|
||||
@ -264,7 +264,7 @@ public:
|
||||
|
||||
template<typename Fx>
|
||||
void for_each( Fx&& fx ) const {
|
||||
typedef meta::is_callable<Fx( std::pair<sol::object, sol::object> )> is_paired;
|
||||
typedef meta::is_invokable<Fx( std::pair<sol::object, sol::object> )> is_paired;
|
||||
for_each(is_paired(), std::forward<Fx>(fx));
|
||||
}
|
||||
|
||||
@ -310,12 +310,12 @@ private:
|
||||
set_resolved_function<R( Args... )>( std::forward<Key>( key ), std::forward<Fx>( fx ) );
|
||||
}
|
||||
|
||||
template<typename Fx, typename Key, meta::EnableIf<meta::is_specialization_of<overload_set, meta::Unqualified<Fx>>> = 0>
|
||||
template<typename Fx, typename Key, meta::enable<meta::is_specialization_of<overload_set, meta::unqualified_t<Fx>>> = meta::enabler>
|
||||
void set_fx( types<>, Key&& key, Fx&& fx ) {
|
||||
set(std::forward<Key>(key), std::forward<Fx>(fx));
|
||||
}
|
||||
|
||||
template<typename Fx, typename Key, typename... Args, meta::DisableIf<meta::is_specialization_of<overload_set, meta::Unqualified<Fx>>> = 0>
|
||||
template<typename Fx, typename Key, typename... Args, meta::disable<meta::is_specialization_of<overload_set, meta::unqualified_t<Fx>>> = meta::enabler>
|
||||
void set_fx( types<>, Key&& key, Fx&& fx, Args&&... args ) {
|
||||
set(std::forward<Key>(key), function_args(std::forward<Fx>(fx), std::forward<Args>(args)...));
|
||||
}
|
||||
@ -344,7 +344,7 @@ public:
|
||||
|
||||
template <typename... Args>
|
||||
static inline table create_with(lua_State* L, Args&&... args) {
|
||||
static const int narr = static_cast<int>(meta::count_if_2_pack<std::is_integral, Args...>::value);
|
||||
static const int narr = static_cast<int>(meta::count_2_for_pack<std::is_integral, Args...>::value);
|
||||
return create(L, narr, static_cast<int>((sizeof...(Args) / 2) - narr), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
@ -378,7 +378,7 @@ public:
|
||||
|
||||
template <typename Name, typename... Args>
|
||||
table create_named(Name&& name, Args&&... args) {
|
||||
static const int narr = static_cast<int>(meta::count_if_2_pack<std::is_integral, Args...>::value);
|
||||
static const int narr = static_cast<int>(meta::count_2_for_pack<std::is_integral, Args...>::value);
|
||||
return create(std::forward<Name>(name), narr, sizeof...(Args) / 2 - narr, std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
@ -44,7 +44,7 @@ private:
|
||||
|
||||
template <typename T>
|
||||
void set( std::true_type, T&& target ) {
|
||||
typedef tie_size<meta::Unqualified<T>> value_size;
|
||||
typedef tie_size<meta::unqualified_t<T>> value_size;
|
||||
typedef tie_size<std::tuple<Tn...>> tie_size;
|
||||
typedef std::conditional_t<(value_size::value < tie_size::value), value_size, tie_size> indices_size;
|
||||
typedef std::make_index_sequence<indices_size::value> indices;
|
||||
@ -64,7 +64,7 @@ public:
|
||||
|
||||
template <typename T>
|
||||
tie_t& operator= ( T&& value ) {
|
||||
typedef is_tieable<meta::Unqualified<T>> bondable;
|
||||
typedef is_tieable<meta::unqualified_t<T>> bondable;
|
||||
set( bondable(), std::forward<T>( value ) );
|
||||
return *this;
|
||||
}
|
||||
|
128
sol/traits.hpp
128
sol/traits.hpp
@ -82,55 +82,61 @@ template<class T, class U, class... Args>
|
||||
struct are_same<T, U, Args...> : std::integral_constant <bool, std::is_same<T, U>::value && are_same<T, Args...>::value> { };
|
||||
|
||||
template<typename T>
|
||||
using Type = typename T::type;
|
||||
using invoke_t = typename T::type;
|
||||
|
||||
template<bool B>
|
||||
using Bool = std::integral_constant<bool, B>;
|
||||
using boolean = std::integral_constant<bool, B>;
|
||||
|
||||
template<typename T>
|
||||
using Not = Bool<!T::value>;
|
||||
using neg = boolean<!T::value>;
|
||||
|
||||
template<typename Condition, typename Then, typename Else>
|
||||
using If = typename std::conditional<Condition::value, Then, Else>::type;
|
||||
|
||||
template<typename Condition, typename Then, typename Else>
|
||||
using TypeIf = typename std::conditional<Condition::value, Type<Then>, Type<Else>>::type;
|
||||
using condition = std::conditional_t<Condition::value, Then, Else>;
|
||||
|
||||
template<typename... Args>
|
||||
struct And : Bool<true> {};
|
||||
struct all : boolean<true> {};
|
||||
|
||||
template<typename T, typename... Args>
|
||||
struct And<T, Args...> : If<T, And<Args...>, Bool<false>> {};
|
||||
struct all<T, Args...> : condition<T, all<Args...>, boolean<false>> {};
|
||||
|
||||
template<typename... Args>
|
||||
struct Or : Bool<false> {};
|
||||
struct any : boolean<false> {};
|
||||
|
||||
template<typename T, typename... Args>
|
||||
struct Or<T, Args...> : If<T, Bool<true>, Or<Args...>> {};
|
||||
struct any<T, Args...> : condition<T, boolean<true>, any<Args...>> {};
|
||||
|
||||
enum class enable_t {
|
||||
_
|
||||
};
|
||||
|
||||
constexpr const auto enabler = enable_t::_;
|
||||
|
||||
template<typename... Args>
|
||||
using EnableIf = typename std::enable_if<And<Args...>::value, int>::type;
|
||||
using enable = std::enable_if_t<all<Args...>::value, enable_t>;
|
||||
|
||||
template<typename... Args>
|
||||
using DisableIf = typename std::enable_if<Not<And<Args...>>::value, int>::type;
|
||||
using disable = std::enable_if_t<neg<all<Args...>>::value, enable_t>;
|
||||
|
||||
template<typename T>
|
||||
using Unqualified = std::remove_cv_t<std::remove_reference_t<T>>;
|
||||
using unqualified = std::remove_cv<std::remove_reference_t<T>>;
|
||||
|
||||
template<typename T>
|
||||
using Unwrapped = typename unwrapped<T>::type;
|
||||
using unqualified_t = typename unqualified<T>::type;
|
||||
|
||||
template<typename T>
|
||||
using unwrapped_t = typename unwrapped<T>::type;
|
||||
|
||||
template <std::size_t N, typename Tuple>
|
||||
using tuple_element = std::tuple_element<N, Unqualified<Tuple>>;
|
||||
using tuple_element = std::tuple_element<N, unqualified_t<Tuple>>;
|
||||
|
||||
template <std::size_t N, typename Tuple>
|
||||
using tuple_element_t = std::tuple_element_t<N, Unqualified<Tuple>>;
|
||||
using tuple_element_t = std::tuple_element_t<N, unqualified_t<Tuple>>;
|
||||
|
||||
template<typename V, typename... Vs>
|
||||
struct find_in_pack_v : Bool<false> { };
|
||||
struct find_in_pack_v : boolean<false> { };
|
||||
|
||||
template<typename V, typename Vs1, typename... Vs>
|
||||
struct find_in_pack_v<V, Vs1, Vs...> : Or<Bool<(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 {
|
||||
template<std::size_t I, typename T, typename... Args>
|
||||
@ -159,27 +165,36 @@ 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...>> {};
|
||||
|
||||
namespace meta_detail {
|
||||
template<std::size_t I, template<typename...> class Pred, typename... Ts>
|
||||
struct count_if_pack : std::integral_constant<std::size_t, 0> {};
|
||||
template<std::size_t I, template<typename...> class Pred, typename T, typename... Ts>
|
||||
struct count_if_pack<I, Pred, T, Ts...> : std::conditional_t<sizeof...(Ts) == 0,
|
||||
std::integral_constant<std::size_t, I + static_cast<std::size_t>(Pred<T>::value)>,
|
||||
count_if_pack<I + static_cast<std::size_t>(Pred<T>::value), Pred, 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> {};
|
||||
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,
|
||||
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...>
|
||||
> { };
|
||||
template<std::size_t I, template<typename...> class Pred, typename... Ts>
|
||||
struct count_if_2_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>
|
||||
struct count_if_2_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)>,
|
||||
count_if_2_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
|
||||
|
||||
template<template<typename...> class Pred, typename... Ts>
|
||||
struct count_if_pack : meta_detail::count_if_pack<0, Pred, Ts...> { };
|
||||
struct count_for_pack : meta_detail::count_for_pack<sizeof...(Ts), 0, Pred, Ts...> { };
|
||||
|
||||
template<template<typename...> class Pred, typename List>
|
||||
struct count_for;
|
||||
|
||||
template<template<typename...> class Pred, typename... Args>
|
||||
struct count_for<Pred, types<Args...>> : count_for_pack<Pred, Args...> {};
|
||||
|
||||
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...> { };
|
||||
|
||||
template<template<typename...> class Pred, typename... Ts>
|
||||
struct count_if_2_pack : meta_detail::count_if_2_pack<0, Pred, Ts...> { };
|
||||
struct count_2_for_pack : meta_detail::count_2_for_pack<0, Pred, Ts...> { };
|
||||
|
||||
template<typename... Args>
|
||||
struct return_type {
|
||||
@ -201,7 +216,7 @@ using return_type_t = typename return_type<Args...>::type;
|
||||
|
||||
namespace meta_detail {
|
||||
template <typename> struct always_true : std::true_type {};
|
||||
struct is_callable_tester {
|
||||
struct is_invokable_tester {
|
||||
template <typename Fun, typename... Args>
|
||||
always_true<decltype(std::declval<Fun>()(std::declval<Args>()...))> static test(int);
|
||||
template <typename...>
|
||||
@ -210,17 +225,17 @@ struct is_callable_tester {
|
||||
} // meta_detail
|
||||
|
||||
template <typename T>
|
||||
struct is_callable;
|
||||
struct is_invokable;
|
||||
template <typename Fun, typename... Args>
|
||||
struct is_callable<Fun(Args...)> : decltype(meta_detail::is_callable_tester::test<Fun, Args...>(0)) {};
|
||||
struct is_invokable<Fun(Args...)> : decltype(meta_detail::is_invokable_tester::test<Fun, Args...>(0)) {};
|
||||
|
||||
namespace meta_detail {
|
||||
|
||||
template<typename T, bool isclass = std::is_class<Unqualified<T>>::value>
|
||||
struct is_function_impl : std::is_function<std::remove_pointer_t<T>> {};
|
||||
template<typename T, bool isclass = std::is_class<unqualified_t<T>>::value>
|
||||
struct is_callable : std::is_function<std::remove_pointer_t<T>> {};
|
||||
|
||||
template<typename T>
|
||||
struct is_function_impl<T, true> {
|
||||
struct is_callable<T, true> {
|
||||
using yes = char;
|
||||
using no = struct { char s[2]; };
|
||||
|
||||
@ -253,7 +268,7 @@ template<class F>
|
||||
struct has_deducible_signature : meta_detail::check_deducible_signature<F>::type { };
|
||||
|
||||
template<typename T>
|
||||
struct Function : Bool<meta_detail::is_function_impl<T>::value> {};
|
||||
struct is_callable : boolean<meta_detail::is_callable<T>::value> {};
|
||||
|
||||
namespace meta_detail {
|
||||
|
||||
@ -269,8 +284,15 @@ using void_tuple_element_t = typename void_tuple_element<I, T>::type;
|
||||
template<typename Signature, bool b = has_deducible_signature<Signature>::value>
|
||||
struct fx_traits {
|
||||
static const bool is_member_function = false;
|
||||
typedef std::tuple<> args_tuple_type;
|
||||
static const std::size_t arity = 0;
|
||||
typedef types<> args_type;
|
||||
typedef std::tuple<> args_tuple_type;
|
||||
typedef void object_type;
|
||||
typedef void function_pointer_type;
|
||||
typedef void function_type;
|
||||
typedef void free_function_pointer_type;
|
||||
typedef void signature_type;
|
||||
typedef void return_type;
|
||||
template<std::size_t i>
|
||||
using arg_at = void_tuple_element_t<i, args_tuple_type>;
|
||||
};
|
||||
@ -376,7 +398,7 @@ template<typename Signature>
|
||||
using function_return_t = typename bind_traits<Signature>::return_type;
|
||||
|
||||
struct has_begin_end_impl {
|
||||
template<typename T, typename U = Unqualified<T>,
|
||||
template<typename T, typename U = unqualified_t<T>,
|
||||
typename B = decltype(std::declval<U&>().begin()),
|
||||
typename E = decltype(std::declval<U&>().end())>
|
||||
static std::true_type test(int);
|
||||
@ -389,7 +411,7 @@ template<typename T>
|
||||
struct has_begin_end : decltype(has_begin_end_impl::test<T>(0)) {};
|
||||
|
||||
struct has_key_value_pair_impl {
|
||||
template<typename T, typename U = Unqualified<T>,
|
||||
template<typename T, typename U = unqualified_t<T>,
|
||||
typename V = typename U::value_type,
|
||||
typename F = decltype(std::declval<V&>().first),
|
||||
typename S = decltype(std::declval<V&>().second)>
|
||||
@ -403,22 +425,32 @@ template<typename T>
|
||||
struct has_key_value_pair : decltype(has_key_value_pair_impl::test<T>(0)) {};
|
||||
|
||||
template <typename T>
|
||||
using is_string_constructible = Or<std::is_same<Unqualified<T>, const char*>, std::is_same<Unqualified<T>, char>, std::is_same<Unqualified<T>, std::string>, std::is_same<Unqualified<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>
|
||||
using is_c_str = Or<
|
||||
std::is_same<std::decay_t<Unqualified<T>>, const char*>,
|
||||
std::is_same<std::decay_t<Unqualified<T>>, char*>,
|
||||
std::is_same<Unqualified<T>, std::string>
|
||||
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>>, char*>,
|
||||
std::is_same<unqualified_t<T>, std::string>
|
||||
>;
|
||||
|
||||
template <typename T>
|
||||
struct is_move_only : all<
|
||||
neg<std::is_reference<T>>,
|
||||
neg<std::is_copy_constructible<unqualified_t<T>>>,
|
||||
std::is_move_constructible<unqualified_t<T>>
|
||||
> {};
|
||||
|
||||
template <typename T>
|
||||
using is_not_move_only = neg<is_move_only<T>>;
|
||||
|
||||
namespace meta_detail {
|
||||
template <typename T, meta::DisableIf<meta::is_specialization_of<std::tuple, meta::Unqualified<T>>> = 0>
|
||||
template <typename T, meta::disable<meta::is_specialization_of<std::tuple, meta::unqualified_t<T>>> = meta::enabler>
|
||||
decltype(auto) force_tuple(T&& x) {
|
||||
return std::forward_as_tuple(std::forward<T>(x));
|
||||
}
|
||||
|
||||
template <typename T, meta::EnableIf<meta::is_specialization_of<std::tuple, meta::Unqualified<T>>> = 0>
|
||||
template <typename T, meta::enable<meta::is_specialization_of<std::tuple, meta::unqualified_t<T>>> = meta::enabler>
|
||||
decltype(auto) force_tuple(T&& x) {
|
||||
return std::forward<T>(x);
|
||||
}
|
||||
@ -442,7 +474,7 @@ auto forward_tuple_impl( std::index_sequence<I...>, Tuple&& tuple ) -> decltype(
|
||||
|
||||
template <typename Tuple>
|
||||
auto forward_tuple( Tuple&& tuple ) {
|
||||
auto x = forward_tuple_impl(std::make_index_sequence<std::tuple_size<meta::Unqualified<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;
|
||||
}
|
||||
|
||||
|
@ -504,11 +504,11 @@ struct lua_type_of<this_state> : std::integral_constant<type, type::none> {};
|
||||
|
||||
template <typename T>
|
||||
struct is_lua_primitive : std::integral_constant<bool,
|
||||
type::userdata != lua_type_of<meta::Unqualified<T>>::value
|
||||
|| std::is_base_of<reference, meta::Unqualified<T>>::value
|
||||
|| std::is_base_of<stack_reference, meta::Unqualified<T>>::value
|
||||
|| meta::is_specialization_of<std::tuple, meta::Unqualified<T>>::value
|
||||
|| meta::is_specialization_of<std::pair, meta::Unqualified<T>>::value
|
||||
type::userdata != lua_type_of<meta::unqualified_t<T>>::value
|
||||
|| std::is_base_of<reference, meta::unqualified_t<T>>::value
|
||||
|| std::is_base_of<stack_reference, meta::unqualified_t<T>>::value
|
||||
|| meta::is_specialization_of<std::tuple, meta::unqualified_t<T>>::value
|
||||
|| meta::is_specialization_of<std::pair, meta::unqualified_t<T>>::value
|
||||
> { };
|
||||
|
||||
template <typename T>
|
||||
@ -539,9 +539,17 @@ struct is_transparent_argument<this_state> : std::true_type {};
|
||||
template <>
|
||||
struct is_transparent_argument<variadic_args> : std::true_type {};
|
||||
|
||||
template <typename Signature>
|
||||
struct lua_bind_traits : meta::bind_traits<Signature> {
|
||||
private:
|
||||
typedef meta::bind_traits<Signature> base_t;
|
||||
public:
|
||||
static const std::size_t arity = base_t::arity - meta::count_for<is_transparent_argument, typename base_t::args_type>::value;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline type type_of() {
|
||||
return lua_type_of<meta::Unqualified<T>>::value;
|
||||
return lua_type_of<meta::unqualified_t<T>>::value;
|
||||
}
|
||||
} // sol
|
||||
|
||||
|
@ -52,7 +52,7 @@ template <>
|
||||
struct is_constructor<no_construction> : std::true_type {};
|
||||
|
||||
template <typename... Args>
|
||||
using has_constructor = meta::Or<is_constructor<meta::Unqualified<Args>>...>;
|
||||
using has_constructor = meta::any<is_constructor<meta::unqualified_t<Args>>...>;
|
||||
|
||||
template <typename T>
|
||||
struct is_destructor : std::false_type {};
|
||||
@ -61,7 +61,7 @@ template <typename Fx>
|
||||
struct is_destructor<destructor_wrapper<Fx>> : std::true_type {};
|
||||
|
||||
template <typename... Args>
|
||||
using has_destructor = meta::Or<is_destructor<meta::Unqualified<Args>>...>;
|
||||
using has_destructor = meta::any<is_destructor<meta::unqualified_t<Args>>...>;
|
||||
|
||||
enum class stage {
|
||||
normalmeta,
|
||||
@ -208,21 +208,21 @@ private:
|
||||
|
||||
template<typename Fx>
|
||||
std::unique_ptr<function_detail::base_function> make_free_function(std::true_type, const std::string&, Fx&& func) {
|
||||
typedef std::decay_t<meta::Unqualified<Fx>> function_type;
|
||||
typedef std::decay_t<meta::unqualified_t<Fx>> function_type;
|
||||
return std::make_unique<function_detail::usertype_function<T, function_type>>(func);
|
||||
}
|
||||
|
||||
template<typename Fx>
|
||||
std::unique_ptr<function_detail::base_function> make_free_function(std::false_type, const std::string&, Fx&& func) {
|
||||
typedef std::decay_t<meta::Unqualified<Fx>> function_type;
|
||||
typedef std::decay_t<meta::unqualified_t<Fx>> function_type;
|
||||
return std::make_unique<function_detail::free_function<function_type>>(func);
|
||||
}
|
||||
|
||||
template<typename... Args, typename Ret>
|
||||
std::unique_ptr<function_detail::base_function> make_function(const std::string& name, Ret(*func)(Args...)) {
|
||||
typedef meta::bind_traits<Ret(Args...)> btraits;
|
||||
typedef lua_bind_traits<Ret(Args...)> btraits;
|
||||
typedef typename btraits::template arg_at<0> Argu;
|
||||
typedef meta::Unqualified<std::remove_pointer_t<Argu>> Arg0;
|
||||
typedef meta::unqualified_t<std::remove_pointer_t<Argu>> Arg0;
|
||||
return make_free_function(std::is_base_of<Arg0, T>(), name, func);
|
||||
}
|
||||
|
||||
@ -248,22 +248,22 @@ private:
|
||||
|
||||
template<typename Fx>
|
||||
std::unique_ptr<function_detail::base_function> make_functor_function(std::true_type, const std::string&, Fx&& func) {
|
||||
typedef std::decay_t<meta::Unqualified<Fx>> function_type;
|
||||
typedef std::decay_t<meta::unqualified_t<Fx>> function_type;
|
||||
return std::make_unique<function_detail::usertype_function<T, function_type>>(func);
|
||||
}
|
||||
|
||||
template<typename Fx>
|
||||
std::unique_ptr<function_detail::base_function> make_functor_function(std::false_type, const std::string&, Fx&& func) {
|
||||
typedef std::decay_t<meta::Unqualified<Fx>> function_type;
|
||||
typedef std::decay_t<meta::unqualified_t<Fx>> function_type;
|
||||
return std::make_unique<function_detail::functor_function<function_type>>(func);
|
||||
}
|
||||
|
||||
template<typename Fx>
|
||||
std::unique_ptr<function_detail::base_function> make_function(const std::string& name, Fx&& func) {
|
||||
typedef meta::Unqualified<Fx> Fxu;
|
||||
typedef meta::bind_traits<Fxu> btraits;
|
||||
typedef meta::unqualified_t<Fx> Fxu;
|
||||
typedef lua_bind_traits<Fxu> btraits;
|
||||
typedef typename btraits::template arg_at<0> Argu;
|
||||
typedef meta::Unqualified<std::remove_pointer_t<Argu>> Arg0;
|
||||
typedef meta::unqualified_t<std::remove_pointer_t<Argu>> Arg0;
|
||||
return make_functor_function(std::is_base_of<Arg0, T>(), name, std::forward<Fx>(func));
|
||||
}
|
||||
|
||||
@ -353,7 +353,7 @@ private:
|
||||
|
||||
template<std::size_t N, typename Fx>
|
||||
void build_function(std::string funcname, Fx&& func) {
|
||||
typedef meta::Or<std::is_member_object_pointer<meta::Unqualified<Fx>>, meta::is_specialization_of<member_property, meta::Unqualified<Fx>>> is_variable;
|
||||
typedef meta::any<std::is_member_object_pointer<meta::unqualified_t<Fx>>, meta::is_specialization_of<member_property, meta::unqualified_t<Fx>>> is_variable;
|
||||
functionnames.push_back(std::move(funcname));
|
||||
std::string& name = functionnames.back();
|
||||
auto baseptr = make_function(name, std::forward<Fx>(func));
|
||||
@ -482,12 +482,12 @@ private:
|
||||
usertype(usertype_detail::add_destructor_tag, Args&&... args) : usertype(usertype_detail::verified, "__gc", default_destructor, std::forward<Args>(args)...) {}
|
||||
|
||||
template<typename... Args>
|
||||
usertype(usertype_detail::check_destructor_tag, Args&&... args) : usertype(meta::If<meta::And<std::is_destructible<T>, meta::Not<usertype_detail::has_destructor<Args...>>>, usertype_detail::add_destructor_tag, usertype_detail::verified_tag>(), std::forward<Args>(args)...) {}
|
||||
usertype(usertype_detail::check_destructor_tag, Args&&... args) : usertype(meta::condition<meta::all<std::is_destructible<T>, meta::neg<usertype_detail::has_destructor<Args...>>>, usertype_detail::add_destructor_tag, usertype_detail::verified_tag>(), std::forward<Args>(args)...) {}
|
||||
|
||||
public:
|
||||
|
||||
template<typename... Args>
|
||||
usertype(Args&&... args) : usertype(meta::If<meta::And<std::is_default_constructible<T>, meta::Not<usertype_detail::has_constructor<Args...>>>, decltype(default_constructor), usertype_detail::check_destructor_tag>(), std::forward<Args>(args)...) {}
|
||||
usertype(Args&&... args) : usertype(meta::condition<meta::all<std::is_default_constructible<T>, meta::neg<usertype_detail::has_constructor<Args...>>>, decltype(default_constructor), usertype_detail::check_destructor_tag>(), std::forward<Args>(args)...) {}
|
||||
|
||||
template<typename... Args, typename... CArgs>
|
||||
usertype(constructors<CArgs...> constructorlist, Args&&... args) : usertype(usertype_detail::verified, "new", constructorlist, "__gc", default_destructor, std::forward<Args>(args)...) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user