lua-users home
lua-l archive

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


hi,
if I want to use tables as keys, is it possible to compare the new key
with existing keys by value (and not by reference) ?

In general, what is the approach in using complex datatypes as keys in tables?

In code:

a={1,2}
b={1,2}
c={}
c["pos"]=a
if c[b]==nil then
	print("c has NOT b as key")
else
	print("c has b as key")
end


This prints "c has NOT b as key".
Is there was a way to tell the c table to use the values stored in a
and b, instead of their references, to check for the presence of that
key ?

I think in java this is the common scenario where a custom equals()
method is implemented to avoid duplicates in a container.

Do I need to implement my own table implementation perhaps?