rrthomas/lua-stdlib — pull request #1 by gvvaughan (2011-12-16 09:31:27+00:00)
Title: tree: fix bugs when using a list of tables as keys 

To be fully general, tree should allow table keys so that it's
possible to write:
$ lua -lstd
> t, k1, k2 = tree.new(), {key='a'}, {key='b'}
> t[{"k1", "k2"}] = "string keys"; t[{k1, k2}] = "table keys"
> = t[{"k1", "k2"}], t[{k1, k2}]
string keys table keys
This patch fixes 3 bugs that prevent that from working.
* src/tree.lua (metatable.__newindex): Detect subtrees correctly
by comparing against the tree metatable, rather than assuming any
"table" type is a correct match.
Use rawset to insert a new node without triggering the __index
metamethod.
(metatable.__index): Don't recurse into table key members, only
the list entries to be folded, by checking whether the table has
a length first - for t[{k1, k2}], {k1, k2} is a list (with length)
and should be folded, but k1 (k1 = {key='a'}) is not a list and
should not.