lua-users home
lua-l archive

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


I recently needed to do something similar to this.  I posted my code here:
http://lua-users.org/wiki/MultipleIndices

It was not meant to be a general-purpose table replacement -- for example, it has fixed 'dimension' and only uses arrays
as keys.  But, maybe you can use it as a launching point to create something specific for your needs.

Good luck,
Evan



Matthew Armstrong wrote:
> Normally, if I index a table with another table as a key, the keying is
> done by the table key's instance (essentially, its address). 
> What I want is for the keying to be defined by the table key's
> _contents_ (the structure of the table).
> 
> For instance, I want to do something like:
> 
> t = makeASpecialTable()
> t[{a=1, b=2}] = 42
> assert(t[{a=1, b=2}] == 42)
> 
> One way to solve this problem is to serialize the table key into
> string.  This works, but probably isn't all that efficient ... or maybe
> making the generated string smaller would help?
> 
> Has anyone dealt with this problem before?