mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
proxy is now pushable, making it usable with functions
This commit is contained in:
parent
20d85850ea
commit
3534bc222c
|
@ -33,8 +33,6 @@ template<typename Table, typename Key>
|
||||||
struct proxy : public proxy_base<proxy<Table, Key>> {
|
struct proxy : public proxy_base<proxy<Table, Key>> {
|
||||||
private:
|
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;
|
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>
|
template<typename T, std::size_t... I>
|
||||||
decltype(auto) tuple_get(std::index_sequence<I...>) const {
|
decltype(auto) tuple_get(std::index_sequence<I...>) const {
|
||||||
|
@ -47,6 +45,8 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Table tbl;
|
||||||
|
key_type key;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
proxy(Table table, T&& key) : tbl(table), key(std::forward<T>(key)) {}
|
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) {
|
inline bool operator!=(const proxy<Table, Key>& right, T&& left) {
|
||||||
return right.template get<std::decay_t<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
|
} // sol
|
||||||
|
|
||||||
#endif // SOL_PROXY_HPP
|
#endif // SOL_PROXY_HPP
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
#include "stack.hpp"
|
#include "stack.hpp"
|
||||||
|
|
||||||
namespace sol {
|
namespace sol {
|
||||||
|
template <typename T>
|
||||||
|
struct idn { typedef T type; };
|
||||||
template <typename Super>
|
template <typename Super>
|
||||||
struct proxy_base {
|
struct proxy_base {
|
||||||
operator std::string() const {
|
operator std::string() const {
|
||||||
|
|
|
@ -371,6 +371,7 @@ template<typename... Args>
|
||||||
struct getter<std::tuple<Args...>> {
|
struct getter<std::tuple<Args...>> {
|
||||||
template <std::size_t... I>
|
template <std::size_t... I>
|
||||||
static decltype(auto) apply(std::index_sequence<I...>, lua_State* L, int index = -1) {
|
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)...);
|
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>
|
template<typename A, typename B>
|
||||||
struct getter<std::pair<A, B>> {
|
struct getter<std::pair<A, B>> {
|
||||||
static decltype(auto) get(lua_State* L, int index = -1) {
|
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));
|
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> {
|
struct field_getter<std::tuple<Args...>, b, C> {
|
||||||
template <std::size_t... I, typename Keys>
|
template <std::size_t... I, typename Keys>
|
||||||
void apply(std::index_sequence<I...>, lua_State* L, Keys&& keys, int tableindex) {
|
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)... });
|
void(detail::swallow{ (get_field<I < 1 && b>(L, detail::forward_get<I>(keys), tableindex), 0)... });
|
||||||
reference saved(L, -1);
|
reference saved(L, -1);
|
||||||
lua_pop(L, static_cast<int>(sizeof...(I) + 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> {
|
struct field_getter<std::pair<A, B>, b, C> {
|
||||||
template <typename Keys>
|
template <typename Keys>
|
||||||
void apply(lua_State* L, Keys&& keys, int tableindex) {
|
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<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);
|
reference saved(L, -1);
|
||||||
lua_pop(L, static_cast<int>(2 + 1));
|
lua_pop(L, static_cast<int>(2 + 1));
|
||||||
saved.push();
|
saved.push();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user