mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
GCC is still not compiling, complaining about detail::ltr_pop and not being able to find a proper overload. I'm not sure why it's complaining, I'll have to look in more detail soon.
This commit is contained in:
parent
17ec059c32
commit
86b16dc61b
|
@ -30,50 +30,25 @@ namespace sol {
|
||||||
class function : virtual public reference {
|
class function : virtual public reference {
|
||||||
private:
|
private:
|
||||||
|
|
||||||
template<typename... Ret>
|
|
||||||
struct invoker {
|
|
||||||
template<typename... Args>
|
|
||||||
static std::tuple<Ret...> call(const function& ref, Args&&... args) {
|
|
||||||
lua_pcall( ref.state( ), sizeof...( Args ), sizeof...( Ret ), 0 );
|
|
||||||
return std::make_tuple(stack::pop<Ret>(ref.state())...);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
struct invoker<> {
|
|
||||||
template<typename... Args>
|
|
||||||
static void call(const function& ref, Args&&... args) {
|
|
||||||
lua_pcall( ref.state( ), sizeof...( Args ), 0, 0 );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct invoker<T> {
|
|
||||||
template<typename... Args>
|
|
||||||
static T call(const function& ref, Args&&... args) {
|
|
||||||
lua_pcall( ref.state( ), sizeof...( Args ), 1, 0 );
|
|
||||||
return stack::pop<T>( ref.state( ) );
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename... Ret>
|
template <typename... Ret>
|
||||||
std::tuple<Ret...> invoke( types<Ret...>, std::size_t n ) {
|
std::tuple<Ret...> call( types<Ret...>, std::size_t n ) {
|
||||||
|
typedef typename std::decay<decltype(std::make_tuple<Ret...>)>::type maketuple_t;
|
||||||
|
maketuple_t m = &std::make_tuple<Ret...>;
|
||||||
lua_pcall( state( ), n, sizeof...( Ret ), 0 );
|
lua_pcall( state( ), n, sizeof...( Ret ), 0 );
|
||||||
return stack::pop_call( state( ), std::make_tuple<Ret...>, types<Ret...>() );
|
return stack::pop_call( state( ), m, types<Ret...>() );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Ret>
|
template <typename Ret>
|
||||||
Ret invoke( types<Ret>, std::size_t n ) {
|
Ret call( types<Ret>, std::size_t n ) {
|
||||||
lua_pcall( state( ), n, 1, 0 );
|
lua_pcall( state( ), n, 1, 0 );
|
||||||
return stack::pop<Ret>( state( ) );
|
return stack::pop<Ret>( state( ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void invoke( types<void>, std::size_t n ) {
|
void call( types<void>, std::size_t n ) {
|
||||||
lua_pcall( state( ), n, 0, 0 );
|
lua_pcall( state( ), n, 0, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void invoke( types<>, std::size_t n ) {
|
void call( types<>, std::size_t n ) {
|
||||||
lua_pcall( state( ), n, 0, 0 );
|
lua_pcall( state( ), n, 0, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,10 +59,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Ret, typename... Args>
|
template<typename... Ret, typename... Args>
|
||||||
auto invoke(Args&&... args) -> decltype(invoke( types<Ret...>( ), sizeof...( Args ) )) {
|
auto invoke(Args&&... args) -> decltype(call(types<Ret...>( ), sizeof...( Args ))) {
|
||||||
push( );
|
push( );
|
||||||
stack::push_args( state( ), std::forward<Args>( args )... );
|
stack::push_args( state( ), std::forward<Args>( args )... );
|
||||||
return invoke( types<Ret...>( ), sizeof...( Args ) );
|
return call( types<Ret...>( ), sizeof...( Args ) );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // sol
|
} // sol
|
||||||
|
|
|
@ -128,7 +128,7 @@ struct explicit_lua_func<TFx, T, true> : public lua_func {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
int operator () (types<void>, types<Args...>, lua_State* L) {
|
int operator () (types<void>, types<Args...> t, lua_State* L) {
|
||||||
stack::pop_call(L, fx, t);
|
stack::pop_call(L, fx, t);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,16 +160,16 @@ inline void push(lua_State* L, indices<I...>, const T& tuplen) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class F, class... Vs>
|
template<class T, class F, class... Vs>
|
||||||
auto ltr_pop(T&& extra, F f, types<>, Vs&&... vs)
|
auto ltr_pop(T&&, F&& f, types<>, Vs&&... vs)
|
||||||
-> decltype(f(std::forward<Vs>(vs)...)) {
|
-> decltype(f(std::forward<Vs>(vs)...)) {
|
||||||
return f(std::forward<Vs>(vs)...);
|
return f(std::forward<Vs>(vs)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
// take head, produce value from it, pass after other values
|
// take head, produce value from it, pass after other values
|
||||||
template<class F, class Head, class... Tail, class... Vs>
|
template<class F, class Head, class... Tail, class... Vs>
|
||||||
auto ltr_pop(lua_State* L, F f, types<Head, Tail...>, Vs&&... vs)
|
auto ltr_pop(lua_State* L, F&& f, types<Head, Tail...>, Vs&&... vs)
|
||||||
-> decltype(ltr_pop(L, f, types<Tail...>{}, std::forward<Vs>(vs)..., pop<Head>(L))) {
|
-> decltype(ltr_pop(L, std::forward<F>(f), types<Tail...>(), std::forward<Vs>(vs)..., pop<Head>(L))) {
|
||||||
return ltr_pop(L, f, types<Tail...>{}, std::forward<Vs>(vs)..., pop<Head>(L));
|
return ltr_pop(L, std::forward<F>(f), types<Tail...>(), std::forward<Vs>(vs)..., pop<Head>(L));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // detail
|
} // detail
|
||||||
|
@ -180,8 +180,8 @@ inline void push(lua_State* L, const std::tuple<Args...>& tuplen) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args, typename TFx>
|
template<typename... Args, typename TFx>
|
||||||
inline auto pop_call(lua_State* L, TFx&& fx, types<Args...> t)->decltype(detail::ltr_pop(L, fx, t)) {
|
inline auto pop_call( lua_State* L, TFx&& fx, types<Args...> )->decltype( detail::ltr_pop( L, std::forward<TFx>( fx ), types<Args...>() ) ) {
|
||||||
return detail::ltr_pop(L, fx, t);
|
return detail::ltr_pop( L, std::forward<TFx>( fx ), types<Args...>());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
|
|
|
@ -89,7 +89,6 @@ private:
|
||||||
|
|
||||||
template<typename T, typename TFx>
|
template<typename T, typename TFx>
|
||||||
table& set_fx(std::false_type, T&& key, TFx&& fx) {
|
table& set_fx(std::false_type, T&& key, TFx&& fx) {
|
||||||
typedef typename std::remove_pointer<typename std::decay<TFx>::type>::type clean_fx;
|
|
||||||
typedef typename std::decay<TFx>::type ptr_fx;
|
typedef typename std::decay<TFx>::type ptr_fx;
|
||||||
std::unique_ptr<detail::lua_func> sptr(new detail::explicit_lua_func<ptr_fx>(std::forward<TFx>(fx)));
|
std::unique_ptr<detail::lua_func> sptr(new detail::explicit_lua_func<ptr_fx>(std::forward<TFx>(fx)));
|
||||||
return set_fx(std::forward<T>(key), std::move(sptr));
|
return set_fx(std::forward<T>(key), std::move(sptr));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user