From 1c617733548a2470515bbd42919213dff586745d Mon Sep 17 00:00:00 2001 From: ThePhD Date: Tue, 3 May 2016 16:49:53 -0400 Subject: [PATCH] Use absolute indices in the places where it's necessary. --- sol/function_types_allocator.hpp | 5 +++-- sol/proxy.hpp | 3 ++- sol/reference.hpp | 2 +- sol/stack_field.hpp | 6 +++--- sol/table_core.hpp | 7 ++++--- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/sol/function_types_allocator.hpp b/sol/function_types_allocator.hpp index 5d463700..94fc2068 100644 --- a/sol/function_types_allocator.hpp +++ b/sol/function_types_allocator.hpp @@ -60,8 +60,9 @@ inline int construct(Match&& matchfx, lua_State* L, int fxarity, int start) { template inline int construct(lua_State* L) { static const auto& meta = usertype_traits::metatable; - call_syntax syntax = stack::get_call_syntax(L, meta, 1); - int argcount = lua_gettop(L) - static_cast(syntax); + int argcount = lua_gettop(L); + call_syntax syntax = argcount > 0 ? stack::get_call_syntax(L, meta, 1) : call_syntax::dot; + argcount -= static_cast(syntax); T** pointerpointer = reinterpret_cast(lua_newuserdata(L, sizeof(T*) + sizeof(T))); T*& referencepointer = *pointerpointer; diff --git a/sol/proxy.hpp b/sol/proxy.hpp index c68c5ad7..c0fe3a99 100644 --- a/sol/proxy.hpp +++ b/sol/proxy.hpp @@ -114,7 +114,8 @@ public: } bool valid () const { - auto p = stack::probe_get_field, global_table>::value>(tbl.lua_state(), key); + stack::push_pop(tbl); + auto p = stack::probe_get_field, global_table>::value>(tbl.lua_state(), key, lua_gettop(tbl.lua_state())); lua_pop(tbl.lua_state(), p.levels); return p; } diff --git a/sol/reference.hpp b/sol/reference.hpp index 2c14cc0b..6a9607c1 100644 --- a/sol/reference.hpp +++ b/sol/reference.hpp @@ -148,7 +148,7 @@ public: inline bool operator== (const reference& l, const reference& r) { auto ppl = stack::push_pop(l); auto ppr = stack::push_pop(r); - return lua_compare(l.lua_state(), -1, -2, LUA_OPEQ) == 0; + return lua_compare(l.lua_state(), -1, -2, LUA_OPEQ) == 1; } inline bool operator!= (const reference& l, const reference& r) { diff --git a/sol/stack_field.hpp b/sol/stack_field.hpp index ed9c4d08..3b576d72 100644 --- a/sol/stack_field.hpp +++ b/sol/stack_field.hpp @@ -168,13 +168,13 @@ struct field_setter, b, C> { template void apply(std::index_sequence, lua_State* L, Key&& keys, Value&& value, int tableindex) { I < 1 ? - set_field(L, detail::forward_get(keys), std::forward(value)) : - set_field(L, detail::forward_get(keys), std::forward(value), tableindex); + set_field(L, detail::forward_get(keys), std::forward(value), tableindex) : + set_field(L, detail::forward_get(keys), std::forward(value)); } template void apply(std::index_sequence, lua_State* L, Keys&& keys, Value&& value, int tableindex) { - get_field(L, detail::forward_get(keys), tableindex); + I0 < 1 ? get_field(L, detail::forward_get(keys), tableindex) : get_field(L, detail::forward_get(keys), -1); apply(std::index_sequence(), L, std::forward(keys), std::forward(value), -1); } diff --git a/sol/table_core.hpp b/sol/table_core.hpp index 2228bed8..800dada2 100644 --- a/sol/table_core.hpp +++ b/sol/table_core.hpp @@ -89,7 +89,8 @@ class basic_table_core : public base_t { auto pp = stack::push_pop(pairs))...>::value)>(*this); void(detail::swallow{ (stack::set_field(base_t::lua_state(), detail::forward_get(pairs), - detail::forward_get(pairs) + detail::forward_get(pairs), + lua_gettop(base_t::lua_state()) ), 0)... }); } @@ -108,7 +109,7 @@ class basic_table_core : public base_t { template decltype(auto) traverse_get_deep_optional( int& popcount, Key&& key ) const { typedef decltype(stack::get(base_t::lua_state())) R; - auto p = stack::probe_get_field(base_t::lua_state(), std::forward(key), -1); + auto p = stack::probe_get_field(base_t::lua_state(), std::forward(key), lua_gettop(base_t::lua_state())); popcount += p.levels; if (!p.success) return R(nullopt); @@ -117,7 +118,7 @@ class basic_table_core : public base_t { template decltype(auto) traverse_get_deep_optional( int& popcount, Key&& key, Keys&&... keys ) const { - auto p = I > 0 ? stack::probe_get_field(base_t::lua_state(), std::forward(key), - 1) : stack::probe_get_field( base_t::lua_state( ), std::forward( key ) ); + auto p = I > 0 ? stack::probe_get_field(base_t::lua_state(), std::forward(key), -1) : stack::probe_get_field( base_t::lua_state( ), std::forward( key ), lua_gettop(base_t::lua_state())); popcount += p.levels; if (!p.success) return T(nullopt);