Модуль:GetField: различия между версиями

Нет описания правки
Нет описания правки
Строка 1093: Строка 1093:


if aPrimitive ~= bPrimitive then
if aPrimitive ~= bPrimitive then
return aPrimitive
return not aPrimitive
end
end


Строка 1100: Строка 1100:


return keys[1]
return keys[1]
end
local function is_wrapper_block_key(key)
return type(key) == "string" and not key:match("^[%a_][%w_]*$")
end
end


Строка 1121: Строка 1125:
end
end


local valueIsPrimitiveArray = is_array_of_primitives(value)
if options.skipPrimitiveRoot and is_array_of_primitives(value) then
if options.skipPrimitiveRoot and is_array_of_primitives(value) then
return
return
Строка 1159: Строка 1162:


if next(v) ~= nil and not is_array_of_primitives(v) then
if next(v) ~= nil and not is_array_of_primitives(v) then
local childPrefix = (type(k) == "string") and key or nil
local childPrefix
if options.nestedKeyMode == "prefixed" then
childPrefix = key
elseif type(k) == "string" then
childPrefix = key
else
childPrefix = nil
end
append_table_fields(parts, v, options, childPrefix)
append_table_fields(parts, v, options, childPrefix)
end
end
Строка 1196: Строка 1206:
skipPrimitiveRoot = true,
skipPrimitiveRoot = true,
}
}
local function is_object_map(tbl)
local count = 0
for k, v in pairs(tbl) do
if type(k) ~= "string" or type(v) ~= "table" then
return false
end
count = count + 1
end
return count > 1
end


local function makeCall(obj)
local function makeCall(obj)
Строка 1220: Строка 1241:


if k == idKey then
if k == idKey then
if type(k) == "string" and string.sub(k, 1, 6) == "!type:" then
if is_wrapper_block_key(k) then
if type(v) == "table" then
if type(v) == "table" then
local json = encode_nowiki_json(v)
if json then
parts[#parts + 1] = "value=" .. tostring(json)
end
append_table_fields(parts, v, rawTypeOptions, nil)
append_table_fields(parts, v, rawTypeOptions, nil)
elseif v ~= nil then
elseif v ~= nil then
Строка 1240: Строка 1265:
elseif v ~= nil then
elseif v ~= nil then
parts[#parts + 1] = "value=" .. tostring(v)
parts[#parts + 1] = "value=" .. tostring(v)
parts[#parts + 1] = k .. "=" .. tostring(v)
end
end
else
else
Строка 1259: Строка 1285:
for _, item in ipairs(data) do
for _, item in ipairs(data) do
makeCall(item)
makeCall(item)
end
elseif is_object_map(data) then
local keys = collect_sorted_keys(data, true)
for _, k in ipairs(keys) do
makeCall({ [k] = data[k] })
end
end
else
else