Open sagamusix opened 1 year ago
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.