Closed DimitarBogdanov closed 1 year ago
For completeness, the following two code samples do not work too:
local t = {}
setmetatable(t, {
__eq = function()
return true
end,
})
print(t == {}) -- should print true, but prints false
local t = {}
t.__eq = function()
return true
end
print(t == {}) -- should print true, but prints false
luau-compile output: https://gist.github.com/DimitarBogdanov/2c72dd31ef5ea465a50e8aca3ee15715 Edit: this is the output from the first code sample
I'm speculating here, but it seems that this would be the reason for the issue: Referenced in compileExprBinary, the compileCompareJump function doesn't seem to check if the type is a table when emitting.
Linked code:
// this is in an if statement which checks if the left value is a constant, which it isn't here
else
{
LuauOpcode opc = getJumpOpCompare(expr->op, not_);
uint8_t rr = compileExprAuto(right, rs);
size_t jumpLabel = bytecode.emitLabel();
if (expr->op == AstExprBinary::CompareGt || expr->op == AstExprBinary::CompareGe)
{
bytecode.emitAD(opc, rr, 0);
bytecode.emitAux(rl);
}
else
{
bytecode.emitAD(opc, rl, 0);
bytecode.emitAux(rr);
}
return jumpLabel;
}
}
Why is this the behavior? It's non-compliant to Lua - and not documented in the compatibility docs.
Luau is based on Lua 5.1 and doesn't include all the changes from later versions. Luau is compliant to Lua 5.1 and 5.2 here.
We will update the compatibility document to note that this change from 5.3 is not supported.
This makes sense. Thank you.
Hello! The
__eq
metamethod does not work, at all.Sample code:
The official Lua demo page correctly runs this code and outputs
true
, but Luau seems to be struggling with it. (tested on Luau 0.596-windows, latest at the time of writing)Also the case with Roblox (on a completely blank workspace):