diff --git a/sol/proxy.hpp b/sol/proxy.hpp index 0093c0cb..d8324ef0 100644 --- a/sol/proxy.hpp +++ b/sol/proxy.hpp @@ -33,8 +33,6 @@ template struct proxy : public proxy_base> { private: typedef meta::If, Key, std::tuple>, Key&, meta::Unqualified>>> key_type; - Table tbl; - key_type key; template decltype(auto) tuple_get(std::index_sequence) const { @@ -47,6 +45,8 @@ private: } public: + Table tbl; + key_type key; template proxy(Table table, T&& key) : tbl(table), key(std::forward(key)) {} @@ -114,6 +114,17 @@ template inline bool operator!=(const proxy& right, T&& left) { return right.template get>() != left; } +namespace stack { +template +struct pusher> { + static int push (lua_State* L, const proxy& p) { + stack::push(L, p.tbl); + int tblindex = lua_gettop(L); + stack::get_field, global_table>::value>(L, p.key, tblindex); + return 1; + } +}; +} // stack } // sol #endif // SOL_PROXY_HPP diff --git a/sol/proxy_base.hpp b/sol/proxy_base.hpp index 037a27fc..10585e76 100644 --- a/sol/proxy_base.hpp +++ b/sol/proxy_base.hpp @@ -27,6 +27,8 @@ #include "stack.hpp" namespace sol { +template +struct idn { typedef T type; }; template struct proxy_base { operator std::string() const { diff --git a/sol/stack.hpp b/sol/stack.hpp index ba2fca94..f50345c3 100644 --- a/sol/stack.hpp +++ b/sol/stack.hpp @@ -371,6 +371,7 @@ template struct getter> { template static decltype(auto) apply(std::index_sequence, lua_State* L, int index = -1) { + index = lua_absindex(L, index); return std::tuple(L, index + I))...>(stack::get(L, index + I)...); } @@ -382,6 +383,7 @@ struct getter> { template struct getter> { static decltype(auto) get(lua_State* L, int index = -1) { + index = lua_absindex(L, index); return std::pair(L, index)), decltype(stack::get(L, index))>(stack::get(L, index), stack::get(L, index + 1)); } }; @@ -780,6 +782,7 @@ template struct field_getter, b, C> { template void apply(std::index_sequence, lua_State* L, Keys&& keys, int tableindex) { + tableindex = lua_absindex(L, tableindex); void(detail::swallow{ (get_field(L, detail::forward_get(keys), tableindex), 0)... }); reference saved(L, -1); lua_pop(L, static_cast(sizeof...(I) + 1)); @@ -796,8 +799,9 @@ template struct field_getter, b, C> { template void apply(lua_State* L, Keys&& keys, int tableindex) { + tableindex = lua_absindex(L, tableindex); get_field(L, detail::forward_get<0>(keys), tableindex); - get_field(L, detail::forward_get<1>(keys), tableindex); + get_field(L, detail::forward_get<1>(keys), tableindex + 1); reference saved(L, -1); lua_pop(L, static_cast(2 + 1)); saved.push();