Jump to content




Weird Metatable Behavior? [Solved]


  • You cannot reply to this topic
2 replies to this topic

#1 Symmetryc

  • Members
  • 434 posts

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 by Symmetryc, 02 December 2013 - 09:28 PM.


#2 distantcam

  • Members
  • 139 posts
  • LocationChunk 0

Posted 02 December 2013 - 09:17 PM

This might help.

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

Quote

"'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 by distantcam, 02 December 2013 - 09:18 PM.


#3 Symmetryc

  • Members
  • 434 posts

Posted 02 December 2013 - 09:22 PM

View Postdistantcam, on 02 December 2013 - 09:17 PM, said:

This might help.

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

Quote

"'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 :/.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users