Модуль:GetField: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| (не показаны 22 промежуточные версии этого же участника) | |||
| Строка 4: | Строка 4: | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
function p.loadCachedData(pagePath) | |||
local titleName = JsonPaths.get(pagePath) | |||
if not titleName or titleName == "" then | |||
if not | |||
return nil | return nil | ||
end | end | ||
local ok, data = pcall(mw.loadData, titleName) | |||
local | if not ok or type(data) ~= "table" then | ||
if | return nil | ||
return nil | |||
end | end | ||
return | return data | ||
end | end | ||
| Строка 37: | Строка 25: | ||
local parsed = {} | local parsed = {} | ||
for part in string.gmatch(path, "([^%.]+)") do | for part in string.gmatch(path, "([^%.]+)") do | ||
parsed[#parsed + 1] = { | local key, idxStr = string.match(part, "^(.-)%[(%d+)%]$") | ||
if key then | |||
parsed[#parsed + 1] = { key, tonumber(idxStr) } | |||
else | |||
local num = tonumber(part) | |||
if num then | |||
parsed[#parsed + 1] = { nil, num } | |||
else | |||
parsed[#parsed + 1] = { part, nil } | |||
end | |||
end | |||
end | end | ||
| Строка 43: | Строка 41: | ||
end | end | ||
local function | local function navigate_path(tbl, path) | ||
if not tbl | if not tbl then return nil end | ||
if not path or path == "" then return tbl end | |||
end | |||
local cur = tbl | local cur = tbl | ||
local start = 1 | |||
local | local len = #path | ||
local | |||
while start <= len do | |||
local dotPos = string.find(path, ".", start, true) | |||
local part | |||
if dotPos then | |||
part = string.sub(path, start, dotPos - 1) | |||
start = dotPos + 1 | |||
else | |||
part = string.sub(path, start) | |||
start = len + 1 | |||
end | |||
if | if type(cur) ~= "table" then return nil end | ||
local bracketPos = string.find(part, "[", 1, true) | |||
if bracketPos then | |||
local key = string.sub(part, 1, bracketPos - 1) | |||
local idx = tonumber(string.sub(part, bracketPos + 1, #part - 1)) | |||
if key ~= "" then | |||
local val = cur[key] | |||
if val == nil then val = cur["!type:" .. key] end | |||
cur = val | |||
end | end | ||
if idx then | |||
if type(cur) ~= "table" then return nil end | |||
cur = cur[idx] | |||
end | end | ||
cur = | else | ||
local num = tonumber(part) | |||
if num then | |||
cur = cur[num] | |||
else | |||
local val = cur[part] | |||
if val == nil then val = cur["!type:" .. part] end | |||
cur = val | |||
end | end | ||
end | end | ||
if cur == nil then | if cur == nil then return nil end | ||
end | end | ||
return cur | return cur | ||
end | end | ||
local function format_value(v) | local function format_value(v) | ||
if v == nil then | if v == nil then | ||
return "" | return "" | ||
| Строка 99: | Строка 103: | ||
return tostring(v) | return tostring(v) | ||
elseif t == "table" then | elseif t == "table" then | ||
local ok, | local ok, json = pcall(mw.text.jsonEncode, v) | ||
if ok and | if ok and json then | ||
return | return json | ||
end | end | ||
return "" | return "" | ||
| Строка 107: | Строка 111: | ||
return tostring(v) | return tostring(v) | ||
end | end | ||
end | end | ||
| Строка 152: | Строка 152: | ||
end | end | ||
local function | function p.ucfirst(s) | ||
if not s or s == "" then return s end | |||
return string.upper(s:sub(1, 1)) .. (s:sub(2) or "") | |||
end | |||
function p.normalizeComponentName(name) | |||
if type(name) ~= "string" or name == "" then | |||
return nil | |||
end | |||
name = mw.text.trim(name) | |||
if name:sub(1, 5) == "type:" then | |||
name = name:sub(6) | |||
elseif name:sub(1, 6) == "!type:" then | |||
name = name:sub(7) | |||
end | |||
if name == "" then | |||
return nil | |||
end | |||
return name | |||
end | |||
local function split_data_page_path(pagePath) | |||
local kind, name = string.match(pagePath or "", "^(component)/([^/]+)%.json$") | |||
if not kind then | |||
return nil, nil | |||
end | |||
return kind, p.ucfirst(name) | |||
end | |||
local function get_component_from_entity(entity, componentName) | |||
if type(entity) ~= "table" or type(entity.components) ~= "table" then | |||
return nil | |||
end | |||
return entity.components["type:" .. componentName] | |||
or entity.components[componentName] | |||
or entity.components["!type:" .. componentName] | |||
end | |||
local function load_specific_entry(pagePath, id, allowDefault) | |||
local kind, name = split_data_page_path(pagePath) | |||
if not kind or not id or id == "" then | |||
return nil | |||
end | |||
if kind ~= "component" then | |||
return nil | |||
end | |||
local base | |||
local defaultData = p.loadCachedData(kind .. "/" .. name .. "/defaultFields.json") | |||
if type(defaultData) == "table" then | |||
base = deep_copy(defaultData) | |||
end | |||
local entityPage = "prototype/Entity/" .. id .. ".json" | |||
local entity = p.loadCachedData(entityPage) | |||
local specific = get_component_from_entity(entity, name) | |||
if type(specific) ~= "table" then | |||
if allowDefault == false then | |||
return nil | |||
end | |||
return base | |||
end | |||
if base then | |||
deep_merge(base, specific) | |||
return base | |||
end | |||
return specific | |||
end | |||
local function resolve_entry_from_data(data, id, allowDefault) | |||
if type(data) ~= "table" then | if type(data) ~= "table" then | ||
return nil | return nil | ||
| Строка 173: | Строка 247: | ||
return merged | return merged | ||
end | end | ||
return | return specific | ||
end | end | ||
end | end | ||
end | end | ||
if allowDefault == false then | |||
if | |||
return nil | return nil | ||
end | end | ||
local base = data["default"] | local base = data["default"] | ||
if type(base) == "table" then | if type(base) == "table" then | ||
return | return base | ||
end | end | ||
| Строка 218: | Строка 264: | ||
end | end | ||
local function | local function load_entry(id, pagePath, data, allowDefault) | ||
if | local specificPageEntry = load_specific_entry(pagePath, id, allowDefault) | ||
return | if specificPageEntry ~= nil then | ||
return specificPageEntry | |||
end | end | ||
data = data or p.loadCachedData(pagePath) | |||
if | if allowDefault == nil then | ||
allowDefault = true | |||
end | end | ||
return resolve_entry_from_data(data, id, allowDefault) | |||
return | |||
end | end | ||
| Строка 256: | Строка 302: | ||
local function contains_target(v, target) | local function contains_target(v, target) | ||
if type(v) == "string" then | |||
return v == target | |||
end | |||
if type(v) == "table" then | if type(v) == "table" then | ||
if is_array(v) then | if is_array(v) then | ||
| Строка 342: | Строка 391: | ||
local parts = {} | local parts = {} | ||
local function walk(tbl, prefix) | local function walk(tbl, prefix) | ||
| Строка 366: | Строка 408: | ||
if type(v) == "table" then | if type(v) == "table" then | ||
if next(v) ~= nil then | if next(v) ~= nil then | ||
local ok, json = pcall(mw.text.jsonEncode, v) | |||
if ok and json then | |||
parts[#parts + 1] = key .. "=<nowiki>" .. json .. "</nowiki>" | |||
end | |||
if is_array(v) then | if is_array(v) then | ||
local first = v[1] | local first = v[1] | ||
| Строка 406: | Строка 451: | ||
local ok, json = pcall(mw.text.jsonEncode, value) | local ok, json = pcall(mw.text.jsonEncode, value) | ||
if ok and json then | if ok and json then | ||
parts[#parts + 1] = key .. "=" .. | parts[#parts + 1] = key .. "=<nowiki>" .. json .. "</nowiki>" | ||
end | end | ||
return | return | ||
| Строка 426: | Строка 471: | ||
if type(key) == "string" and key ~= "" and not seen[key] then | if type(key) == "string" and key ~= "" and not seen[key] then | ||
seen[key] = true | seen[key] = true | ||
append_flattened_part(parts, key, | append_flattened_part(parts, key, navigate_path(entry, key)) | ||
end | end | ||
end | end | ||
| Строка 465: | Строка 510: | ||
end | end | ||
local function build_tpl(id, pagePath, tplPath, data, tplArgs) | local function build_tpl(id, pagePath, tplPath, data, tplArgs, preEntry, strictExact) | ||
if id == "" or pagePath == "" or tplPath == "" then | if id == "" or pagePath == "" or tplPath == "" then | ||
return "" | return "" | ||
end | end | ||
local | local entry | ||
if strictExact then | |||
if | entry = load_entry(id, pagePath, data, false) | ||
else | |||
entry = preEntry or load_entry(id, pagePath, data) | |||
end | |||
if entry == nil then | |||
return "" | return "" | ||
end | end | ||
local extra = flatten_entry(entry) | local extra = flatten_entry(entry) | ||
local extraTplArgs = tplArgs or "" | local extraTplArgs = tplArgs or "" | ||
| Строка 499: | Строка 548: | ||
local searchId = args[1] or "" | local searchId = args[1] or "" | ||
local kind = (args[2] or ""):lower() | local kind = (args[2] or ""):lower() | ||
local fieldId = args[3] or "" | local fieldId = p.ucfirst(args[3] or "") | ||
if searchId == "" or fieldId == "" then | if searchId == "" or fieldId == "" then | ||
| Строка 509: | Строка 558: | ||
local storeName = (kind == "prototype") and "prototype_store.json" or "component_store.json" | local storeName = (kind == "prototype") and "prototype_store.json" or "component_store.json" | ||
local | local data = p.loadCachedData(storeName) | ||
if not data then | if not data then | ||
return "" | return "" | ||
| Строка 546: | Строка 594: | ||
end | end | ||
local entry = load_entry(id, pagePath) or {} | |||
local entry = | |||
return flatten_entry(entry) | return flatten_entry(entry) | ||
end | end | ||
| Строка 570: | Строка 612: | ||
end | end | ||
local entry = load_entry(id, pagePath) or {} | |||
local entry = | |||
local parts = flatten_selected_parts(entry, keys) | local parts = flatten_selected_parts(entry, keys) | ||
if #parts == 0 then | if #parts == 0 then | ||
| Строка 595: | Строка 631: | ||
end | end | ||
local entry = load_entry(id, pagePath) | |||
local entry = | |||
if entry == nil then | if entry == nil then | ||
return "" | return "" | ||
| Строка 610: | Строка 640: | ||
end | end | ||
return format_value(navigate_path(entry, keyPath)) | |||
end | end | ||
| Строка 649: | Строка 678: | ||
if key and key ~= "" then | if key and key ~= "" then | ||
nextCur = tbl[key] | nextCur = tbl[key] | ||
if nextCur == nil then | if nextCur == nil then nextCur = tbl["!type:" .. key] end | ||
else | else | ||
nextCur = tbl | nextCur = tbl | ||
| Строка 701: | Строка 728: | ||
return false | return false | ||
end | |||
local function split_csv_list(text) | |||
text = mw.text.unstripNoWiki(text or "") | |||
local out = {} | |||
for part in string.gmatch(text, "([^,]+)") do | |||
part = mw.text.trim(part) | |||
if part ~= "" then | |||
out[#out + 1] = part | |||
end | |||
end | |||
return out | |||
end | end | ||
| Строка 717: | Строка 758: | ||
end | end | ||
local | local data = p.loadCachedData(pagePath) | ||
if not data then | if not data then | ||
return "[]" | return "[]" | ||
| Строка 737: | Строка 777: | ||
for _, idKey in ipairs(ids) do | for _, idKey in ipairs(ids) do | ||
local entry = | local entry = resolve_entry_from_data(data, idKey) | ||
if type(entry) == "table" and entry_matches_path(entry, parsedPath, target, searchType) then | if type(entry) == "table" and entry_matches_path(entry, parsedPath, target, searchType) then | ||
matches[#matches + 1] = idKey | matches[#matches + 1] = idKey | ||
| Строка 746: | Строка 786: | ||
return "" | return "" | ||
end | end | ||
local ok, json = pcall(mw.text.jsonEncode, matches) | |||
if ok and json then | |||
return json | |||
end | |||
return "" | |||
end | |||
local function collect_ids_from_entry(entry) | |||
local out = {} | |||
local seen = {} | |||
local function add(v) | |||
if v == nil then | |||
return | |||
end | |||
local s = tostring(v) | |||
if s ~= "" and not seen[s] then | |||
seen[s] = true | |||
out[#out + 1] = s | |||
end | |||
end | |||
if type(entry) == "table" then | |||
if is_array(entry) then | |||
for _, v in ipairs(entry) do | |||
add(v) | |||
end | |||
else | |||
for _, v in pairs(entry) do | |||
if type(v) == "table" and is_array(v) then | |||
for _, item in ipairs(v) do | |||
add(item) | |||
end | |||
elseif type(v) ~= "table" then | |||
add(v) | |||
end | |||
end | |||
end | |||
else | |||
add(entry) | |||
end | |||
return out | |||
end | |||
function p.search(frame) | |||
local args = getArgs(frame, { removeBlanks = false }) | |||
local mode = (args[1] or ""):lower() | |||
local rawList = args[2] or "" | |||
if mode ~= "component" and mode ~= "tag" then | |||
return "" | |||
end | |||
local targets = split_csv_list(rawList) | |||
if #targets == 0 then | |||
return "" | |||
end | |||
local pagePath = (mode == "component") and "component.json" or "tag.json" | |||
local data = p.loadCachedData(pagePath) | |||
if not data then | |||
return "" | |||
end | |||
local matches = {} | |||
local seen = {} | |||
local function add_id(id) | |||
local s = tostring(id) | |||
if s ~= "" and not seen[s] then | |||
seen[s] = true | |||
matches[#matches + 1] = s | |||
end | |||
end | |||
for _, key in ipairs(targets) do | |||
local entry = resolve_entry_from_data(data, key) | |||
if entry ~= nil then | |||
local ids = collect_ids_from_entry(entry) | |||
for _, id in ipairs(ids) do | |||
add_id(id) | |||
end | |||
end | |||
end | |||
table.sort(matches, function(a, b) | |||
return tostring(a) < tostring(b) | |||
end) | |||
local ok, json = pcall(mw.text.jsonEncode, matches) | local ok, json = pcall(mw.text.jsonEncode, matches) | ||
| Строка 785: | Строка 916: | ||
end | end | ||
local | local data = p.loadCachedData(pagePath) | ||
if not data then | if not data then | ||
return "" | return "" | ||
| Строка 802: | Строка 932: | ||
local matches = {} | local matches = {} | ||
local entryCache = {} | |||
if searchType == "path" then | if searchType == "path" then | ||
for _, idKey in ipairs(ids) do | for _, idKey in ipairs(ids) do | ||
local entry = | local entry = resolve_entry_from_data(data, idKey) | ||
entryCache[idKey] = entry | |||
if type(entry) == "table" and entry_has_any_nonempty_path(entry, parsedPath) then | if type(entry) == "table" and entry_has_any_nonempty_path(entry, parsedPath) then | ||
matches[#matches + 1] = idKey | matches[#matches + 1] = idKey | ||
| Строка 813: | Строка 945: | ||
local target = tostring(searchValue) | local target = tostring(searchValue) | ||
for _, idKey in ipairs(ids) do | for _, idKey in ipairs(ids) do | ||
local entry = | local entry = resolve_entry_from_data(data, idKey) | ||
entryCache[idKey] = entry | |||
if type(entry) == "table" and entry_matches_path(entry, parsedPath, target, searchType) then | if type(entry) == "table" and entry_matches_path(entry, parsedPath, target, searchType) then | ||
matches[#matches + 1] = idKey | matches[#matches + 1] = idKey | ||
| Строка 826: | Строка 959: | ||
local out = {} | local out = {} | ||
for _, idKey in ipairs(matches) do | for _, idKey in ipairs(matches) do | ||
local tpl = build_tpl(idKey, pagePath, tplPath, data, tplArgs) | local tpl = build_tpl(idKey, pagePath, tplPath, data, tplArgs, entryCache[idKey], true) | ||
if tpl ~= "" then | if tpl ~= "" then | ||
out[#out + 1] = tpl | out[#out + 1] = tpl | ||
| Строка 852: | Строка 985: | ||
end | end | ||
local data = frame.data | local data = frame.data | ||
local tplStr = build_tpl(id, pagePath, tplPath, data, tplArgs, nil, true) | |||
local tplStr = build_tpl(id, pagePath, tplPath, data, tplArgs) | |||
return preprocess_or_return(frame, tplStr) | return preprocess_or_return(frame, tplStr) | ||
end | end | ||
| Строка 869: | Строка 994: | ||
local searchId = args[1] or "" | local searchId = args[1] or "" | ||
local kind = (args[2] or ""):lower() | local kind = (args[2] or ""):lower() | ||
local generatorId = args[3] or "" | local generatorId = p.ucfirst(args[3] or "") | ||
local tplPath = mw.text.unstripNoWiki(args[4] or "") | local tplPath = mw.text.unstripNoWiki(args[4] or "") | ||
local tplArgs = args[5] or args.tplArgs or args.templateArgs or "" | local tplArgs = args[5] or args.tplArgs or args.templateArgs or "" | ||
| Строка 890: | Строка 1015: | ||
end | end | ||
local | local data = p.loadCachedData(pagePath) | ||
if not data then | if not data then | ||
return "" | return "" | ||
| Строка 898: | Строка 1022: | ||
local out = {} | local out = {} | ||
for _, id in ipairs(ids) do | for _, id in ipairs(ids) do | ||
local tpl = build_tpl(id, pagePath, tplPath, data, tplArgs) | local entry = resolve_entry_from_data(data, id) | ||
if entry ~= nil then | |||
local tpl = build_tpl(id, pagePath, tplPath, data, tplArgs, entry, true) | |||
if tpl ~= "" then | |||
out[#out + 1] = tpl | |||
end | |||
end | end | ||
end | end | ||
| Строка 916: | Строка 1043: | ||
local searchId = args[1] or "" | local searchId = args[1] or "" | ||
local kind = (args[2] or ""):lower() | local kind = (args[2] or ""):lower() | ||
local generatorId = args[3] or "" | local generatorId = p.ucfirst(args[3] or "") | ||
if searchId == "" or generatorId == "" then | if searchId == "" or generatorId == "" then | ||
| Строка 937: | Строка 1064: | ||
return "" | return "" | ||
end | |||
function p.loadEntityData(entityId) | |||
if entityId == "" then | |||
return nil | |||
end | |||
local pagePath = "prototype/Entity/" .. entityId .. ".json" | |||
return p.loadCachedData(pagePath) | |||
end | |||
function p.entityHasComponent(entity, compName) | |||
if type(entity) ~= "table" or type(entity.components) ~= "table" then | |||
return false | |||
end | |||
return entity.components[compName] ~= nil | |||
or entity.components["type:" .. compName] ~= nil | |||
or entity.components["!type:" .. compName] ~= nil | |||
end | |||
function p.collectEntityComponents(entity) | |||
if type(entity) ~= "table" or type(entity.components) ~= "table" then | |||
return {} | |||
end | |||
local out = {} | |||
local seen = {} | |||
local comps = entity.components | |||
if #comps > 0 then | |||
for _, v in ipairs(comps) do | |||
local name = p.normalizeComponentName(v) | |||
if name and not seen[name] then | |||
seen[name] = true | |||
out[#out + 1] = name | |||
end | |||
end | |||
else | |||
for k in pairs(comps) do | |||
local name = p.normalizeComponentName(k) | |||
if name and not seen[name] then | |||
seen[name] = true | |||
out[#out + 1] = name | |||
end | |||
end | |||
end | |||
table.sort(out) | |||
return out | |||
end | end | ||
| Строка 948: | Строка 1125: | ||
end | end | ||
local | local entity = p.loadEntityData(entityId) | ||
if not entity then | |||
if not | |||
return "false" | return "false" | ||
end | end | ||
return p.entityHasComponent(entity, compName) and "true" or "false" | |||
return " | end | ||
function p.getComp(frame) | |||
local args = getArgs(frame, { removeBlanks = false }) | |||
local entityId = args[1] or "" | |||
if entityId == "" then | |||
return "" | |||
end | end | ||
local | local entity = p.loadEntityData(entityId) | ||
if | if not entity then | ||
return " | return "" | ||
end | end | ||
local | local out = p.collectEntityComponents(entity) | ||
local ok, json = pcall(mw.text.jsonEncode, out) | |||
if ok and json then | |||
return json | |||
end | end | ||
return " | return "" | ||
end | end | ||
| Строка 983: | Строка 1165: | ||
end | end | ||
local | local data = p.loadCachedData(pagePath) | ||
if not data then | if not data then | ||
return "" | return "" | ||
end | end | ||
local idsTable = data.id | local idsTable = data.id or data | ||
if type(idsTable) ~= "table" then | if type(idsTable) ~= "table" then | ||
return "" | return "" | ||
| Строка 1034: | Строка 1215: | ||
end | end | ||
local | local data = p.loadCachedData(pagePath) | ||
if not data then | if not data then | ||
return "" | return "" | ||
end | end | ||
local idsTable = data.id | local idsTable = data.id or data | ||
if type(idsTable) ~= "table" then | if type(idsTable) ~= "table" then | ||
return "" | return "" | ||
| Строка 1048: | Строка 1228: | ||
for idKey in pairs(idsTable) do | for idKey in pairs(idsTable) do | ||
local tpl = build_tpl(idKey, pagePath, tplPath, data, tplArgs) | local entry = resolve_entry_from_data(data, idKey) | ||
if entry ~= nil then | |||
local tpl = build_tpl(idKey, pagePath, tplPath, data, tplArgs, entry, true) | |||
if tpl ~= "" then | |||
out[#out + 1] = tpl | |||
end | |||
end | end | ||
end | end | ||
| Строка 1063: | Строка 1246: | ||
local ok, json = pcall(mw.text.jsonEncode, value) | local ok, json = pcall(mw.text.jsonEncode, value) | ||
if ok and json then | if ok and json then | ||
return | return "<nowiki>" .. json .. "</nowiki>" | ||
end | end | ||
return nil | return nil | ||
| Строка 1142: | Строка 1325: | ||
local json = encode_nowiki_json(value) | local json = encode_nowiki_json(value) | ||
if json then | if json then | ||
parts[#parts + 1] = prefix .. "=" .. | parts[#parts + 1] = prefix .. "=" .. json | ||
end | end | ||
end | end | ||
| Строка 1162: | Строка 1345: | ||
local json = encode_nowiki_json(v) | local json = encode_nowiki_json(v) | ||
if json then | if json then | ||
parts[#parts + 1] = key .. "=" .. | parts[#parts + 1] = key .. "=" .. json | ||
end | end | ||
elseif options.nestedKeyMode == "raw" then | elseif options.nestedKeyMode == "raw" then | ||
local json = encode_nowiki_json(v) | local json = encode_nowiki_json(v) | ||
if json then | if json then | ||
parts[#parts + 1] = key .. "=" .. | parts[#parts + 1] = key .. "=" .. json | ||
end | end | ||
end | end | ||
| Строка 1260: | Строка 1443: | ||
local json = encode_nowiki_json(v) | local json = encode_nowiki_json(v) | ||
if json then | if json then | ||
parts[#parts + 1] = "value=" .. | parts[#parts + 1] = "value=" .. json | ||
end | end | ||
append_table_fields(parts, v, rawTypeOptions, nil) | append_table_fields(parts, v, rawTypeOptions, nil) | ||
| Строка 1270: | Строка 1453: | ||
local json = encode_nowiki_json(v) | local json = encode_nowiki_json(v) | ||
if json then | if json then | ||
parts[#parts + 1] = "value=" .. | parts[#parts + 1] = "value=" .. json | ||
end | end | ||
end | end | ||
| Строка 1352: | Строка 1535: | ||
local pairPattern = mw.text.unstripNoWiki(args.pattern or "(.*)") | local pairPattern = mw.text.unstripNoWiki(args.pattern or "(.*)") | ||
local pairReplace = mw.text.unstripNoWiki(args.replace or "\\1") | local pairReplace = mw.text.unstripNoWiki(args.replace or "\\1") | ||
local maxItems = tonumber(args.max or args.limit or args.max_count or args.maxCount or "") | |||
if maxItems ~= nil then | |||
maxItems = math.floor(maxItems) | |||
if maxItems < 0 then | |||
maxItems = nil | |||
end | |||
end | |||
local out = {} | local out = {} | ||
if is_array(data) then | if is_array(data) then | ||
local processed = 0 | |||
for _, v in ipairs(data) do | for _, v in ipairs(data) do | ||
processed = processed + 1 | |||
if maxItems ~= nil and processed > maxItems then | |||
break | |||
end | |||
local text = "" | local text = "" | ||
| Строка 1399: | Строка 1597: | ||
return tostring(a) < tostring(b) | return tostring(a) < tostring(b) | ||
end) | end) | ||
local processed = 0 | |||
for _, k in ipairs(keys) do | for _, k in ipairs(keys) do | ||
processed = processed + 1 | |||
if maxItems ~= nil and processed > maxItems then | |||
break | |||
end | |||
local v = data[k] | local v = data[k] | ||
local vStr | local vStr | ||
| Строка 1455: | Строка 1660: | ||
return frame:preprocess(table.concat(out, " ")) | return frame:preprocess(table.concat(out, " ")) | ||
end | end | ||
end | |||
function p.flattenFieldSelectiveDirect(id, dataPage, paramNames) | |||
if id == "" or dataPage == "" or type(paramNames) ~= "table" or #paramNames == 0 then | |||
return "" | |||
end | |||
local entry = load_entry(id, dataPage) or {} | |||
local parts = flatten_selected_parts(entry, paramNames) | |||
if #parts == 0 then | |||
return "" | |||
end | |||
return table.concat(parts, "|") | |||
end | end | ||
return p | return p | ||