lua-users home
lua-l archive

__eq in shared metatables

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


Hi,
Is there any reason why __eq is not called when the metatable is shared for a
type other than table and userdata?
$ lua
Lua 5.1.1 Copyright (C) 1994-2006 Lua.org, PUC-Rio
> debug.setmetatable(0, {
>> __len=function(x) return x end,
>> __eq=function(x,y) print(x,y) return x<=y and y<=x end
>> })
> print(#1)
1
> print(3==4)
false
Since there are thoughts of honoring __len for tables, it would be nice to
honor __eq as well. Also, I couldn't find this kind of behavior documented in
the reference manual: the manual only mentions that __eq should be called if
two objects have the same type and __eq metamethod.
Cheers,
Luis.
-- 
A mathematician is a device for turning coffee into theorems.
 -- P. Erdos 
-- 
Luis Carvalho
Applied Math PhD Student - Brown University
PGP Key: E820854A <carvalho@dam.brown.edu>

AltStyle によって変換されたページ (->オリジナル) /