* luci/libs: util: further enhancements to table serialisation
This commit is contained in:
parent
2975bb66a6
commit
33ef3a1da2
1 changed files with 14 additions and 7 deletions
|
@ -437,19 +437,26 @@ function _serialize_table(t, seen)
|
||||||
seen[t] = true
|
seen[t] = true
|
||||||
|
|
||||||
local data = ""
|
local data = ""
|
||||||
for i = 1, #t do
|
local idata = ""
|
||||||
local v = serialize_data(t[i], seen)
|
local ilen = 0
|
||||||
data = data .. ( #data > 0 and ", " or "" ) .. v
|
|
||||||
end
|
|
||||||
for k, v in pairs(t) do
|
for k, v in pairs(t) do
|
||||||
if type(k) ~= "number" then
|
if type(k) ~= "number" or k < 1 or math.floor(k) ~= k or ( k - #t ) > 3 then
|
||||||
k = serialize_data(k, seen)
|
k = serialize_data(k, seen)
|
||||||
v = serialize_data(v, seen)
|
v = serialize_data(v, seen)
|
||||||
data = data .. ( #data > 0 and ", " or "" ) ..
|
data = data .. ( #data > 0 and ", " or "" ) ..
|
||||||
'[' .. k .. '] = ' .. v
|
'[' .. k .. '] = ' .. v
|
||||||
|
elseif k > ilen then
|
||||||
|
ilen = k
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return data
|
|
||||||
|
for i = 1, ilen do
|
||||||
|
local v = serialize_data(t[i], seen)
|
||||||
|
idata = idata .. ( #idata > 0 and ", " or "" ) .. v
|
||||||
|
end
|
||||||
|
|
||||||
|
return idata .. ( #data > 0 and ", " or "" ) .. data
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Recursively serialize given data to lua code, suitable for restoring
|
--- Recursively serialize given data to lua code, suitable for restoring
|
||||||
|
|
Loading…
Reference in a new issue