Ha ha haaa I forgot std::pair is a tuple-like type .-.

This commit is contained in:
ThePhD 2016-03-14 18:33:10 -04:00
parent 83ec159da1
commit 20d85850ea
3 changed files with 42 additions and 1 deletions

View File

@ -63,7 +63,7 @@ public:
}
template<typename T>
T get() const {
decltype(auto) get() const {
return stack::get<T>(L, index);
}

View File

@ -379,6 +379,13 @@ struct getter<std::tuple<Args...>> {
}
};
template<typename A, typename B>
struct getter<std::pair<A, B>> {
static decltype(auto) get(lua_State* L, int index = -1) {
return std::pair<decltype(stack::get<A>(L, index)), decltype(stack::get<B>(L, index))>(stack::get<A>(L, index), stack::get<B>(L, index + 1));
}
};
template <typename T, type expected, typename>
struct checker {
template <typename Handler>
@ -487,6 +494,15 @@ struct popper<std::tuple<Args...>> {
}
};
template <typename A, typename B>
struct popper<std::pair<A, B>> {
inline decltype(auto) pop(lua_State* L) {
decltype(auto) r = get<std::pair<A, B>>(L, lua_gettop(L) - 2 + 1);
lua_pop(L, 2);
return r;
}
};
template<typename T, typename>
struct pusher {
template <typename... Args>
@ -741,6 +757,16 @@ struct pusher<std::tuple<Args...>> {
}
};
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 T, bool, typename>
struct field_getter {
template <typename Key>
@ -766,6 +792,18 @@ struct field_getter<std::tuple<Args...>, b, C> {
}
};
template <typename A, typename B, bool b, typename C>
struct field_getter<std::pair<A, B>, b, C> {
template <typename Keys>
void apply(lua_State* L, Keys&& keys, int tableindex) {
get_field<b>(L, detail::forward_get<0>(keys), tableindex);
get_field<false>(L, detail::forward_get<1>(keys), tableindex);
reference saved(L, -1);
lua_pop(L, static_cast<int>(2 + 1));
saved.push();
}
};
template <typename T>
struct field_getter<T, true, std::enable_if_t<meta::is_c_str<T>::value>> {
template <typename Key>

View File

@ -286,6 +286,9 @@ struct is_proxy_primitive<std::reference_wrapper<T>> : std::true_type { };
template <typename... Args>
struct is_proxy_primitive<std::tuple<Args...>> : std::true_type { };
template <typename A, typename B>
struct is_proxy_primitive<std::pair<A, B>> : std::true_type { };
template <typename T>
struct is_unique_usertype : std::false_type {};