mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
multi_return<>
name to return_type<>
.
Makes more sense, as the return does not always have to be multiple types. (Indeed, it is specialized for 1 and 0 cases).
This commit is contained in:
parent
be839bdcd2
commit
d7ea4718c8
|
@ -68,12 +68,12 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Ret, typename... Args>
|
template<typename... Ret, typename... Args>
|
||||||
typename multi_return<Ret...>::type operator()(types<Ret...>, Args&&... args) {
|
typename return_type<Ret...>::type operator()(types<Ret...>, Args&&... args) {
|
||||||
return call<Ret...>(std::forward<Args>(args)...);
|
return call<Ret...>(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Ret, typename... Args>
|
template<typename... Ret, typename... Args>
|
||||||
typename multi_return<Ret...>::type call(Args&&... args) {
|
typename return_type<Ret...>::type call(Args&&... 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 invoke(types<Ret...>(), sizeof...(Args));
|
||||||
|
|
|
@ -45,7 +45,7 @@ struct static_function {
|
||||||
|
|
||||||
template<typename... Ret, typename... Args>
|
template<typename... Ret, typename... Args>
|
||||||
static int typed_call(types<Ret...>, types<Args...> t, function_type* fx, lua_State* L) {
|
static int typed_call(types<Ret...>, types<Args...> t, function_type* fx, lua_State* L) {
|
||||||
typedef typename multi_return<Ret...>::type return_type;
|
typedef typename return_type<Ret...>::type return_type;
|
||||||
return_type r = stack::pop_call(L, fx, t);
|
return_type r = stack::pop_call(L, fx, t);
|
||||||
stack::push(L, std::move(r));
|
stack::push(L, std::move(r));
|
||||||
return sizeof...(Ret);
|
return sizeof...(Ret);
|
||||||
|
@ -82,7 +82,7 @@ struct static_member_function {
|
||||||
|
|
||||||
template<typename... Ret, typename... Args>
|
template<typename... Ret, typename... Args>
|
||||||
static int typed_call(types<Ret...>, types<Args...>, T& item, function_type& ifx, lua_State* L) {
|
static int typed_call(types<Ret...>, types<Args...>, T& item, function_type& ifx, lua_State* L) {
|
||||||
typedef typename multi_return<Ret...>::type return_type;
|
typedef typename return_type<Ret...>::type return_type;
|
||||||
auto fx = [&item, &ifx](Args&&... args) -> return_type { return (item.*ifx)(std::forward<Args>(args)...); };
|
auto fx = [&item, &ifx](Args&&... args) -> return_type { return (item.*ifx)(std::forward<Args>(args)...); };
|
||||||
return_type r = stack::pop_call(L, fx, types<Args...>());
|
return_type r = stack::pop_call(L, fx, types<Args...>());
|
||||||
stack::push(L, std::move(r));
|
stack::push(L, std::move(r));
|
||||||
|
@ -173,7 +173,7 @@ struct functor_function : public base_function {
|
||||||
|
|
||||||
template<typename... Ret, typename... Args>
|
template<typename... Ret, typename... Args>
|
||||||
int operator()(types<Ret...>, types<Args...> t, lua_State* L) {
|
int operator()(types<Ret...>, types<Args...> t, lua_State* L) {
|
||||||
typedef typename multi_return<Ret...>::type return_type;
|
typedef typename return_type<Ret...>::type return_type;
|
||||||
return_type r = stack::pop_call(L, fx, t);
|
return_type r = stack::pop_call(L, fx, t);
|
||||||
stack::push(L, r);
|
stack::push(L, r);
|
||||||
return sizeof...(Ret);
|
return sizeof...(Ret);
|
||||||
|
@ -217,7 +217,7 @@ struct member_function : public base_function {
|
||||||
|
|
||||||
template<typename... Ret, typename... Args>
|
template<typename... Ret, typename... Args>
|
||||||
int operator()(types<Ret...>, types<Args...> t, lua_State* L) {
|
int operator()(types<Ret...>, types<Args...> t, lua_State* L) {
|
||||||
typedef typename multi_return<Ret...>::type return_type;
|
typedef typename return_type<Ret...>::type return_type;
|
||||||
return_type r = stack::pop_call(L, fx, t);
|
return_type r = stack::pop_call(L, fx, t);
|
||||||
stack::push(L, std::move(r));
|
stack::push(L, std::move(r));
|
||||||
return sizeof...(Ret);
|
return sizeof...(Ret);
|
||||||
|
@ -269,7 +269,7 @@ struct userdata_function : public base_function {
|
||||||
|
|
||||||
template<typename... Ret, typename... Args>
|
template<typename... Ret, typename... Args>
|
||||||
int operator()(types<Ret...>, types<Args...> t, lua_State* L) {
|
int operator()(types<Ret...>, types<Args...> t, lua_State* L) {
|
||||||
typedef typename multi_return<Ret...>::type return_type;
|
typedef typename return_type<Ret...>::type return_type;
|
||||||
return_type r = stack::pop_call(L, fx, t);
|
return_type r = stack::pop_call(L, fx, t);
|
||||||
stack::push(L, std::move(r));
|
stack::push(L, std::move(r));
|
||||||
return sizeof...(Ret);
|
return sizeof...(Ret);
|
||||||
|
|
|
@ -101,7 +101,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Ret, typename... Args>
|
template<typename... Ret, typename... Args>
|
||||||
typename multi_return<Ret...>::type call(Args&&... args) {
|
typename return_type<Ret...>::type call(Args&&... args) {
|
||||||
return tbl.get<function>(key)(types<Ret...>(), std::forward<Args>(args)...);
|
return tbl.get<function>(key)(types<Ret...>(), std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -129,7 +129,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args, typename... Keys>
|
template<typename... Args, typename... Keys>
|
||||||
typename multi_return<Args...>::type get(Keys&&... keys) const {
|
typename return_type<Args...>::type get(Keys&&... keys) const {
|
||||||
return global.get(types<Args...>(), std::forward<Keys>(keys)...);
|
return global.get(types<Args...>(), std::forward<Keys>(keys)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ class table : public reference {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Tup, typename... Ret, std::size_t... I>
|
template<typename Tup, typename... Ret, std::size_t... I>
|
||||||
typename multi_return<Ret...>::type tuple_get(types<Ret...> t, indices<I...>, Tup&& tup) const {
|
typename return_type<Ret...>::type tuple_get(types<Ret...> t, indices<I...>, Tup&& tup) const {
|
||||||
return std::make_tuple(element_get<I>(t, std::forward<Tup>(tup))...);
|
return std::make_tuple(element_get<I>(t, std::forward<Tup>(tup))...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ class table : public reference {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Ret, typename... Keys>
|
template<typename... Ret, typename... Keys>
|
||||||
typename multi_return<Ret...>::type get(types<Ret...> t, Keys&&... keys) const {
|
typename return_type<Ret...>::type get(types<Ret...> t, Keys&&... keys) const {
|
||||||
static_assert(sizeof...(Keys) == sizeof...(Ret), "Must have same number of keys as return values");
|
static_assert(sizeof...(Keys) == sizeof...(Ret), "Must have same number of keys as return values");
|
||||||
return tuple_get(t, t, std::make_tuple(std::forward<Keys>(keys)...));
|
return tuple_get(t, t, std::make_tuple(std::forward<Keys>(keys)...));
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Ret, typename... Keys>
|
template<typename... Ret, typename... Keys>
|
||||||
typename multi_return<Ret...>::type get(Keys&&... keys) const {
|
typename return_type<Ret...>::type get(Keys&&... keys) const {
|
||||||
return get(types<Ret...>(), std::forward<Keys>(keys)...);
|
return get(types<Ret...>(), std::forward<Keys>(keys)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,17 +39,17 @@ template<typename T>
|
||||||
using Decay = typename std::decay<T>::type;
|
using Decay = typename std::decay<T>::type;
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
struct multi_return {
|
struct return_type {
|
||||||
typedef std::tuple<Args...> type;
|
typedef std::tuple<Args...> type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct multi_return<T> {
|
struct return_type<T> {
|
||||||
typedef T type;
|
typedef T type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct multi_return<> : types<>{
|
struct return_type<> : types<>{
|
||||||
typedef void type;
|
typedef void type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user