Skip to content

Commit 1c61773

Browse files
committed
Use absolute indices in the places where it's necessary.
1 parent 2aa5ab7 commit 1c61773

File tree

5 files changed

+13
-10
lines changed

5 files changed

+13
-10
lines changed

sol/function_types_allocator.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ inline int construct(Match&& matchfx, lua_State* L, int fxarity, int start) {
6060
template <typename T, typename... TypeLists>
6161
inline int construct(lua_State* L) {
6262
static const auto& meta = usertype_traits<T>::metatable;
63-
call_syntax syntax = stack::get_call_syntax(L, meta, 1);
64-
int argcount = lua_gettop(L) - static_cast<int>(syntax);
63+
int argcount = lua_gettop(L);
64+
call_syntax syntax = argcount > 0 ? stack::get_call_syntax(L, meta, 1) : call_syntax::dot;
65+
argcount -= static_cast<int>(syntax);
6566

6667
T** pointerpointer = reinterpret_cast<T**>(lua_newuserdata(L, sizeof(T*) + sizeof(T)));
6768
T*& referencepointer = *pointerpointer;

sol/proxy.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ struct proxy : public proxy_base<proxy<Table, Key>> {
114114
}
115115

116116
bool valid () const {
117-
auto p = stack::probe_get_field<std::is_same<meta::Unqualified<Table>, global_table>::value>(tbl.lua_state(), key);
117+
stack::push_pop(tbl);
118+
auto p = stack::probe_get_field<std::is_same<meta::Unqualified<Table>, global_table>::value>(tbl.lua_state(), key, lua_gettop(tbl.lua_state()));
118119
lua_pop(tbl.lua_state(), p.levels);
119120
return p;
120121
}

sol/reference.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class reference {
148148
inline bool operator== (const reference& l, const reference& r) {
149149
auto ppl = stack::push_pop(l);
150150
auto ppr = stack::push_pop(r);
151-
return lua_compare(l.lua_state(), -1, -2, LUA_OPEQ) == 0;
151+
return lua_compare(l.lua_state(), -1, -2, LUA_OPEQ) == 1;
152152
}
153153

154154
inline bool operator!= (const reference& l, const reference& r) {

sol/stack_field.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,13 @@ struct field_setter<std::tuple<Args...>, b, C> {
168168
template <bool g, std::size_t I, typename Key, typename Value>
169169
void apply(std::index_sequence<I>, lua_State* L, Key&& keys, Value&& value, int tableindex) {
170170
I < 1 ?
171-
set_field<g>(L, detail::forward_get<I>(keys), std::forward<Value>(value)) :
172-
set_field<g>(L, detail::forward_get<I>(keys), std::forward<Value>(value), tableindex);
171+
set_field<g>(L, detail::forward_get<I>(keys), std::forward<Value>(value), tableindex) :
172+
set_field<g>(L, detail::forward_get<I>(keys), std::forward<Value>(value));
173173
}
174174

175175
template <bool g, std::size_t I0, std::size_t I1, std::size_t... I, typename Keys, typename Value>
176176
void apply(std::index_sequence<I0, I1, I...>, lua_State* L, Keys&& keys, Value&& value, int tableindex) {
177-
get_field<g>(L, detail::forward_get<I0>(keys), tableindex);
177+
I0 < 1 ? get_field<g>(L, detail::forward_get<I0>(keys), tableindex) : get_field<g>(L, detail::forward_get<I0>(keys), -1);
178178
apply<false>(std::index_sequence<I1, I...>(), L, std::forward<Keys>(keys), std::forward<Value>(value), -1);
179179
}
180180

sol/table_core.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ class basic_table_core : public base_t {
8989
auto pp = stack::push_pop<top_level && (is_global<decltype(detail::forward_get<I * 2>(pairs))...>::value)>(*this);
9090
void(detail::swallow{ (stack::set_field<top_level>(base_t::lua_state(),
9191
detail::forward_get<I * 2>(pairs),
92-
detail::forward_get<I * 2 + 1>(pairs)
92+
detail::forward_get<I * 2 + 1>(pairs),
93+
lua_gettop(base_t::lua_state())
9394
), 0)... });
9495
}
9596

@@ -108,7 +109,7 @@ class basic_table_core : public base_t {
108109
template <bool global, typename T, std::size_t I, typename Key>
109110
decltype(auto) traverse_get_deep_optional( int& popcount, Key&& key ) const {
110111
typedef decltype(stack::get<T>(base_t::lua_state())) R;
111-
auto p = stack::probe_get_field<global>(base_t::lua_state(), std::forward<Key>(key), -1);
112+
auto p = stack::probe_get_field<global>(base_t::lua_state(), std::forward<Key>(key), lua_gettop(base_t::lua_state()));
112113
popcount += p.levels;
113114
if (!p.success)
114115
return R(nullopt);
@@ -117,7 +118,7 @@ class basic_table_core : public base_t {
117118

118119
template <bool global, typename T, std::size_t I, typename Key, typename... Keys>
119120
decltype(auto) traverse_get_deep_optional( int& popcount, Key&& key, Keys&&... keys ) const {
120-
auto p = I > 0 ? stack::probe_get_field<global>(base_t::lua_state(), std::forward<Key>(key), - 1) : stack::probe_get_field<global>( base_t::lua_state( ), std::forward<Key>( key ) );
121+
auto p = I > 0 ? stack::probe_get_field<global>(base_t::lua_state(), std::forward<Key>(key), -1) : stack::probe_get_field<global>( base_t::lua_state( ), std::forward<Key>( key ), lua_gettop(base_t::lua_state()));
121122
popcount += p.levels;
122123
if (!p.success)
123124
return T(nullopt);

0 commit comments

Comments
 (0)