-- public domain 20080407 lua@ztact.com require 'ztact' -- tree manipulation ---------------------------------------- tree manipulation -- adding a node... -- without ztact.set a = a or {} a.b = a.b or {} a.b.c = a.b.c or {} a.b.c.d = 1 -- with ztact.set: a = a or {} ztact.set (a, 'b', 'c', 'd', 1) -- determining if a node exists... -- without ztact.get if a and a.b and a.b.c and a.b.c.d == 1 then -- do something end -- with ztact.get if ztact.get (a, 'b', 'c', 'd') == 1 then -- do something end -- clearing a node (that may not exist!) -- without ztact.set -- Note that the below does not collapse the now empty branch -- a.b.c, it only -- removes the leaf 'd'. if a and a.b and a.b.c then a.b.c.d = nil end -- with ztact.set -- Note that the below will also collapse the empty branch a.b.c, so -- that a will again be an empty table. ztact.set (a, 'b', 'c', 'd', nil)