proxy is now pushable, making it usable with functions

This commit is contained in:
ThePhD 2016-03-15 05:20:56 -04:00
parent 20d85850ea
commit 3534bc222c
3 changed files with 20 additions and 3 deletions

View File

@ -33,8 +33,6 @@ template<typename Table, typename Key>
struct proxy : public proxy_base<proxy<Table, Key>> {
private:
typedef meta::If<meta::is_specialization_of<Key, std::tuple>, Key, std::tuple<meta::If<std::is_array<meta::Unqualified<Key>>, Key&, meta::Unqualified<Key>>>> key_type;
Table tbl;
key_type key;
template<typename T, std::size_t... I>
decltype(auto) tuple_get(std::index_sequence<I...>) const {
@ -47,6 +45,8 @@ private:
}
public:
Table tbl;
key_type key;
template<typename T>
proxy(Table table, T&& key) : tbl(table), key(std::forward<T>(key)) {}
@ -114,6 +114,17 @@ template<typename Table, typename Key, typename T>
inline bool operator!=(const proxy<Table, Key>& right, T&& left) {
return right.template get<std::decay_t<T>>() != left;
}
namespace stack {
template <typename Table, typename Key>
struct pusher<proxy<Table, Key>> {
static int push (lua_State* L, const proxy<Table, Key>& p) {
stack::push(L, p.tbl);
int tblindex = lua_gettop(L);
stack::get_field<std::is_same<meta::Unqualified<Table>, global_table>::value>(L, p.key, tblindex);
return 1;
}
};
} // stack
} // sol
#endif // SOL_PROXY_HPP

View File

@ -27,6 +27,8 @@
#include "stack.hpp"
namespace sol {
template <typename T>
struct idn { typedef T type; };
template <typename Super>
struct proxy_base {
operator std::string() const {

View File

@ -371,6 +371,7 @@ template<typename... Args>
struct getter<std::tuple<Args...>> {
template <std::size_t... I>
static decltype(auto) apply(std::index_sequence<I...>, lua_State* L, int index = -1) {
index = lua_absindex(L, index);
return std::tuple<decltype(stack::get<Args>(L, index + I))...>(stack::get<Args>(L, index + I)...);
}
@ -382,6 +383,7 @@ 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) {
index = lua_absindex(L, index);
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));
}
};
@ -780,6 +782,7 @@ template <typename... Args, bool b, typename C>
struct field_getter<std::tuple<Args...>, b, C> {
template <std::size_t... I, typename Keys>
void apply(std::index_sequence<I...>, lua_State* L, Keys&& keys, int tableindex) {
tableindex = lua_absindex(L, tableindex);
void(detail::swallow{ (get_field<I < 1 && b>(L, detail::forward_get<I>(keys), tableindex), 0)... });
reference saved(L, -1);
lua_pop(L, static_cast<int>(sizeof...(I) + 1));
@ -796,8 +799,9 @@ 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) {
tableindex = lua_absindex(L, tableindex);
get_field<b>(L, detail::forward_get<0>(keys), tableindex);
get_field<false>(L, detail::forward_get<1>(keys), tableindex);
get_field<false>(L, detail::forward_get<1>(keys), tableindex + 1);
reference saved(L, -1);
lua_pop(L, static_cast<int>(2 + 1));
saved.push();