This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Symmetryc's profile picture

Weird Metatable Behavior? [Solved]

Started by Symmetryc, 02 December 2013 - 07:05 PM
Symmetryc #1
Posted 02 December 2013 - 08:05 PM
Alright so I have this code:

local t = setmetatable({}, {__eq = function(left, right) print("hi") return true end})
print(t == 5)
But for some reason it won't print "hi", does anyone have an explanation? Probably something dumb that I missed :/
Edited on 02 December 2013 - 08:28 PM
distantcam #2
Posted 02 December 2013 - 09:17 PM
This might help.

http://lua-users.org...8/msg00469.html

"'eq': the == operation. The function getcomphandler defines how Lua chooses a
metamethod for comparison operators. A metamethod only is selected when both
objects being compared have the same type and the same metamethod for the
selected operation."
Edited on 02 December 2013 - 08:18 PM
Symmetryc #3
Posted 02 December 2013 - 09:22 PM
This might help.

http://lua-users.org...8/msg00469.html

"'eq': the == operation. The function getcomphandler defines how Lua chooses a
metamethod for comparison operators. A metamethod only is selected when both
objects being compared have the same type and the same metamethod for the
selected operation."
That's really weird functionality (suppose you wanted your object to be equal to the string "Hello" or something), but I guess that's how it is :/.