libs/core: Add luci.util.create_dtable
authorSteven Barth <steven@midlink.org>
Mon, 28 Jul 2008 13:07:22 +0000 (13:07 +0000)
committerSteven Barth <steven@midlink.org>
Mon, 28 Jul 2008 13:07:22 +0000 (13:07 +0000)
libs/core/luasrc/util.lua

index 48b6fa0..22f295d 100644 (file)
@@ -375,6 +375,19 @@ function clone(object, deep)
        return copy
 end
 
+
+--- Create a dynamic table which automatically creates subtables.
+-- @return     Dynamic Table
+function create_dtable()
+        return setmetatable({}, { __index =
+                function(tbl, key)
+                        return rawget(tbl, key)
+                         or rawget(rawset(tbl, key, create_dtable()), key)
+                end
+        })
+end
+
+
 -- Serialize the contents of a table value.
 function _serialize_table(t)
        local data = ""