lua-users home
lua-l archive

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

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?