From: Steven Barth Date: Mon, 28 Jul 2008 13:07:22 +0000 (+0000) Subject: libs/core: Add luci.util.create_dtable X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=84ad4e3e21b53c84cb6d1dc6f6dbae97e24f9d94;p=openwrt-luci.git libs/core: Add luci.util.create_dtable --- diff --git a/libs/core/luasrc/util.lua b/libs/core/luasrc/util.lua index 48b6fa063c..22f295d23f 100644 --- a/libs/core/luasrc/util.lua +++ b/libs/core/luasrc/util.lua @@ -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 = ""