In Lua, does indexing a table with a table as the key call the __eq metamethod?

StackOverflow https://stackoverflow.com/questions/23173525

  •  06-07-2023
  •  | 
  •  

Frage

I am wondering if table[key] where key is a table with a metatable will call the __eq metamethod. For instance, if the table has a key "a" and the __eq metamethod returns true if "a" is being compared to the metatable, will indexing the table with the table return the value for "a"?

War es hilfreich?

Lösung

No, indexing uses raw equality: http://www.lua.org/manual/5.2/manual.html#2.4

You should consider explicitly converting your objects to their string representation before indexing instead of relying on implicit metamethods.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top