Модуль:GetField: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 918: | Строка 918: | ||
return "false" | return "false" | ||
end | |||
function p.getComp(frame) | |||
local args = getArgs(frame, { removeBlanks = false }) | |||
local entityId = args[1] or "" | |||
if entityId == "" then | |||
return "[]" | |||
end | |||
local moduleName = JsonPaths.get("component.json") | |||
local data = load_cached_data(moduleName) | |||
if not data or type(data) ~= "table" then | |||
return "[]" | |||
end | |||
local entry = data[entityId] | |||
if type(entry) ~= "table" then | |||
return "[]" | |||
end | |||
local out = {} | |||
for _, v in ipairs(entry) do | |||
if v ~= nil and v ~= "" then | |||
out[#out + 1] = v | |||
end | |||
end | |||
local ok, json = pcall(mw.text.jsonEncode, out) | |||
if ok and json then | |||
return json | |||
end | |||
return "[]" | |||
end | end | ||