Модуль:GetField: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 353: | Строка 353: | ||
end | end | ||
local function flatten_parts(entry) | local function flatten_parts(entry, prefix) | ||
if type(entry) ~= "table" then | if type(entry) ~= "table" then | ||
return {} | return {} | ||
end | end | ||
prefix = prefix or "" | |||
local parts = {} | local parts = {} | ||
local function qualify(key) | |||
if prefix == "" then | |||
return key | |||
end | |||
return prefix .. "." .. key | |||
end | |||
local function append_table_json(key, value) | local function append_table_json(key, value) | ||
| Строка 367: | Строка 375: | ||
end | end | ||
local function walk(tbl, | local function walk(tbl, curPrefix) | ||
local keys = {} | local keys = {} | ||
for k in pairs(tbl) do | for k in pairs(tbl) do | ||
| Строка 379: | Строка 387: | ||
local v = tbl[k] | local v = tbl[k] | ||
local kStr = tostring(k) | local kStr = tostring(k) | ||
local key = ( | local key = (curPrefix == "" and kStr or curPrefix .. "." .. kStr) | ||
if type(v) == "table" then | if type(v) == "table" then | ||
| Строка 399: | Строка 407: | ||
end | end | ||
walk(entry, | walk(entry, prefix) | ||
return parts | return parts | ||
end | end | ||
| Строка 897: | Строка 905: | ||
end | end | ||
function p.flattenParams(entry) | function p.flattenParams(entry, prefix) | ||
return flatten_parts(entry) | return flatten_parts(entry, prefix) | ||
end | end | ||
| Строка 1083: | Строка 1091: | ||
if type(obj) == "table" then | if type(obj) == "table" then | ||
local extra = p.flattenParams(obj) | local extra = p.flattenParams(obj, id) | ||
for i = 1, #extra do | for i = 1, #extra do | ||
parts[#parts + 1] = extra[i] | parts[#parts + 1] = extra[i] | ||