You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using the current develop branch of sol. I have a custom container that is automatically detected by sol, so I did not specialize usertype_container for my container. However, deleting the last element of the container does not work as documented. Here is the current default implementation of set:
staticintset(lua_State* L_) {
stack_object value = stack_object(L_, raw_index(3));
ifconstexpr (is_linear_integral::value) {
// for non-associative containers,// erasure only happens if it is the// last index in the containerauto key = stack::get<K>(L_, 2);
auto self_size = deferred_uc::size(L_);
if (key == static_cast<K>(self_size)) {
if (type_of(L_, 3) == type::lua_nil) {
returnerase(L_);
}
}
}
else {
if (type_of(L_, 3) == type::lua_nil) {
returnerase(L_);
}
}
auto& self = get_src(L_);
detail::error_result er = set_start(L_, self, stack_object(L_, raw_index(2)), std::move(value));
returnhandle_errors(L_, er);
}
Of interest is the line auto self_size = deferred_uc::size(L_);. You'd expect that if a container has 10 elements, it would return 10, but in fact it returns 1, because size returns the number of elements pushed to the Lua stack instead:
As a consequence, container[#container]=nil is only doing the intended thing when #container == 1.
From my understanding, size is implemented as intended, but set needs to read the container size from the stack instead of from the size return value.
The text was updated successfully, but these errors were encountered:
I'm also not completely sure but shouldn't erase be called if the key isn't pointing to the last element of the container? After all that's what is being done for associative containers well. Maybe I am doing something wrong but right now I cannot do container[42] = nil from Lua because nil is not compatible with a reference to the object type in my container - and if I add an operator= (sol::optional<my_type>), sol doesn't recognize that the required assignment operator exists anymore.
I'm using the current develop branch of sol. I have a custom container that is automatically detected by sol, so I did not specialize
usertype_container
for my container. However, deleting the last element of the container does not work as documented. Here is the current default implementation ofset
:Of interest is the line
auto self_size = deferred_uc::size(L_);
. You'd expect that if a container has 10 elements, it would return 10, but in fact it returns 1, becausesize
returns the number of elements pushed to the Lua stack instead:As a consequence,
container[#container]=nil
is only doing the intended thing when#container == 1
.From my understanding,
size
is implemented as intended, butset
needs to read the container size from the stack instead of from thesize
return value.The text was updated successfully, but these errors were encountered: