X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=libs%2Fcore%2Fluasrc%2Futil.lua;h=a4ea2d29f889059f5176c8880f533300885ada2b;hp=48b6fa063cffc625c1a00f6ff188f15aae369d79;hb=8c3ee6f9b7e5ab0b4edbf4838c7c1a9ee6d7df5d;hpb=e5df13e80e7b652492e6d2b26afca43e94262e29 diff --git a/libs/core/luasrc/util.lua b/libs/core/luasrc/util.lua index 48b6fa063..a4ea2d29f 100644 --- a/libs/core/luasrc/util.lua +++ b/libs/core/luasrc/util.lua @@ -320,7 +320,7 @@ end --- Combines two or more numerically indexed tables into one. -- @param tbl1 Table value to combine -- @param tbl2 Table value to combine --- @param tblN More values to combine +-- @param ... More tables to combine -- @return Table value containing all values of given tables function combine(...) local result = {} @@ -375,6 +375,19 @@ function clone(object, deep) return copy end + +--- Create a dynamic table which automatically creates subtables. +-- @return Dynamic Table +function dtable() + return setmetatable({}, { __index = + function(tbl, key) + return rawget(tbl, key) + or rawget(rawset(tbl, key, dtable()), key) + end + }) +end + + -- Serialize the contents of a table value. function _serialize_table(t) local data = ""