From 84ad4e3e21b53c84cb6d1dc6f6dbae97e24f9d94 Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Mon, 28 Jul 2008 13:07:22 +0000 Subject: [PATCH] libs/core: Add luci.util.create_dtable --- libs/core/luasrc/util.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 = "" -- 2.11.0