So I want to make a comparison to return true when I compare an object to nil.
Code:
local null = setmetatable({}, {
__eq = function(self, Value)
print("Check!")
return Value == nil
end,
})
print(null == nil)
print(null == {})
Output:
Default Lua:
Luau:
As you can see outputs differ among both languages.
-
Lua documentation states it will not run __eq, if you are comparing your object with nil, function, string, or other native object. However, it runs __eq when you attempt to compare it to another table or userdata.
-
Luau doesn’t say anything at all, so I assume is probably the same behavior. The output claims is different though and it just works when I compare the object to itself.
The documentation on the __eq metamethod in Roblox is no more than “The == equal to operator” which doesn’t help at all with this issue.
The issue with this code is that is not running at all the __eq function in the metatable.
If you know what’s the actual problem in this code please let me know.