lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

In the “changes” section of the 5.3 docs it says:

"The Table library now respects metamethods for setting and getting elements.”

I had to read section 2.1 again and run some tests before I figured this doesn’t apply to the use (or not) of __eq metamethods on a table’s elements when indexing into it, only for the functions in the table library respecting __index and __newindex metamethods defined on the tables themselves. Can I suggest that for clarity, the above bit has something added to it like “note, this does not apply to the use of an element’s __eq metamethod when indexing into a table, which still follows the raw equality comparison rules described in section 2.1”

Maybe it’s just me, but in my head I was sure that 5.3 no longer used raw equality for table indexing, ah well.

On a tangent now, but would such a change ever be considered, or are there performance impacts that make it impractical? Thinking about it some more, is this restriction ultimately due to there not being a way of changing the hash function of an object to comply with the different definition of equality in the __eq metamethod? That would totally make sense and I can understand that fast hashing is quite pivotal to Lua’s efficiency.