Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 12: | Строка 12: | ||
local function parse_indexed_part(part) | local function parse_indexed_part(part) | ||
local key, idx = string.match(part, "^(.-)%[(%d+)%]$") | local key, idx = string.match(part, "^(.-)%[(%d+)%]$") | ||
if key then | if key then | ||
return key, tonumber(idx) | return key, tonumber(idx) | ||
end | end | ||
local num = tonumber(part) | local num = tonumber(part) | ||
if num then | if num then | ||
| Строка 32: | Строка 30: | ||
local key, idx = parse_indexed_part(part) | local key, idx = parse_indexed_part(part) | ||
if key and key ~= "" then | if key and key ~= "" then | ||
cur = cur[key] | local nextCur = nil | ||
if type(cur) == "table" then | |||
nextCur = cur[key] | |||
if nextCur == nil then | |||
nextCur = cur["!type:" .. key] | |||
end | |||
end | |||
cur = nextCur | |||
end | end | ||
if idx then | if idx then | ||
if type(cur) ~= "table" then | if type(cur) ~= "table" then | ||
return nil | return nil | ||
| Строка 53: | Строка 57: | ||
for _ in pairs(t) do | for _ in pairs(t) do | ||
i = i + 1 | i = i + 1 | ||
end | end | ||
local n = 0 | local n = 0 | ||
for k in pairs(t) do | for k in pairs(t) do | ||
| Строка 72: | Строка 74: | ||
return tostring(v) | return tostring(v) | ||
elseif t == "table" then | elseif t == "table" then | ||
if is_array(v) then | if is_array(v) then | ||
local out = {} | local out = {} | ||
| Строка 82: | Строка 83: | ||
return table.concat(out, ", ") | return table.concat(out, ", ") | ||
else | else | ||
local out = {} | local out = {} | ||
for k, val in pairs(v) do | for k, val in pairs(v) do | ||
| Строка 94: | Строка 94: | ||
end | end | ||
function p.get(frame) | function p.get(frame) | ||
local args = frame.args or {} | local args = frame.args or {} | ||
| Строка 101: | Строка 100: | ||
local keyPath = args[3] or "" | local keyPath = args[3] or "" | ||
local baseUser = "User:IanComradeBot/" | |||
local baseUser = "IanComradeBot/" | |||
local moduleName = "Module:" .. baseUser .. pagePath .. "/data" | local moduleName = "Module:" .. baseUser .. pagePath .. "/data" | ||
local ok, data = pcall(mw.loadData, moduleName) | local ok, data = pcall(mw.loadData, moduleName) | ||
if not ok or not data then | if not ok or not data then | ||
return "" | |||
end | end | ||
local entry = nil | local entry = nil | ||
if id ~= "" then | if id ~= "" then | ||
| Строка 129: | Строка 120: | ||
if keyPath == "" then | if keyPath == "" then | ||
return format_value(entry) | return format_value(entry) | ||
end | end | ||