[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: using tables as keys
- From: Alexander Gladysh <agladysh@...>
- Date: Tue, 20 Jul 2010 11:42:07 +0400
On Tue, Jul 20, 2010 at 11:38, Valerio Schiavoni
<valerio.schiavoni@gmail.com> wrote:
> 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?
<...>
> 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?
You need to do your comparison manually.
In general, this is not a trivial task (tables may contain
cross-references etc.).
See this for complete (I think) implementation:
http://github.com/lua-nucleo/lua-nucleo/blob/master/lua-nucleo/tdeepequals.lua
Alexander.