This behavior was recently changed. When someone pushes a std::shared_ptr<T> that is nullptr, and then tries to get a std::shared_ptr out in a C++ function, it would crash and/or fail because we pushed nil and not a userdata that was nullptr.
This scenario, of course, now creates the problem you're seeing here.
I might be able to massage this to behave better by using a metatables == operator, but I need to test if it even kicks in for this case.
Behavior similar to the addition operation, except that Lua will try a metamethod only when the values being compared are either both tables or both full userdata and they are not primitively equal. The result of the call is always converted to a boolean.
So we're a little screwed at this point. The best thing I can suggest is writing a function is_nil. That, or we would have to let returning a nullptr result in pushing nil into Lua, but ultimately disallow void func (std::shared_ptr<T>&/std::unique_ptr<T>&/my_special_ptr<T>&) from being a thing.
That way, if someone passes nil to that function, it won't crash? There's a lot of design choices here and I'm honestly not sure which is the right one.
Hi, I'm not sure what the expected behaviour is, but in an older version of sol2 this was giving nil as I expect, so maybe there's a bug here?
I've simplified it to the following test case:
Lua is printing false when I expect it should be true.
The text was updated successfully, but these errors were encountered: