From: Steven Barth Date: Mon, 28 Jul 2008 13:07:22 +0000 (+0000) Subject: libs/core: Add luci.util.create_dtable X-Git-Tag: 0.8.0~562 X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fluci.git;a=commitdiff_plain;h=84ad4e3e21b53c84cb6d1dc6f6dbae97e24f9d94 libs/core: Add luci.util.create_dtable --- diff --git a/libs/core/luasrc/util.lua b/libs/core/luasrc/util.lua index 48b6fa063..22f295d23 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 = ""