[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: using tables as keys
- From: Valerio Schiavoni <valerio.schiavoni@...>
- Date: Tue, 20 Jul 2010 09:38:06 +0200
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?