I’m having a very basic problem here: I can’t seem to get the __lt, __le, or __eq metamethods to work in studio. Code that runs just fine, like the example below, on other interpreters fails on Roblox. I doubt this is a bug since it is a Lua feature probably used in lots of games, but I can’t seem to figure out what I’m doing wrong. I even reinstalled studio!
local mt = {}
function mt:__lt(other)
return self[1] < other
end
print(setmetatable({1}, mt) < 3)
--> Workspace.Script:6: attempt to compare table with number
"Unlike arithmetic metamethods, relational metamethods do not support mixed types. Their behavior for mixed types mimics the common behavior of these operators in Lua. If you try to compare a string with a number for order, Lua raises an error. Similarly, if you try to compare two objects with different metamethods for order, Lua raises an error.
An equality comparison never raises an error, but if two objects have different metamethods, the equality operation results in false, without even calling any metamethod. Again, this behavior mimics the common behavior of Lua, which always classifies strings as different from numbers, regardless of their values. Lua calls the equality metamethod only when the two objects being compared share this metamethod."-Programming in Lua : 13.2
Ah, the interpreter I was using since I haven’t installed Lua on my windows machine is found here, which apparently runs version 5.3.5. The spec must have changed somewhere between 5.0 (the version that manual was written for) and 5.3.5.