Модуль:GetField: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 39: | Строка 39: | ||
local function format_value(v) | local function format_value(v) | ||
local okJson, json = pcall(mw.text.jsonEncode, v) | |||
if okJson and json == "null" then | |||
return "null" | |||
end | |||
if v == nil then return "" end | if v == nil then return "" end | ||
local t = type(v) | local t = type(v) | ||
if t == "string" or t == "number" or t == "boolean" then | if t == "string" or t == "number" or t == "boolean" then | ||
return tostring(v) | return tostring(v) | ||
elseif t == "table" then | elseif t == "table" then | ||
local ok, | local ok, json2 = pcall(mw.text.jsonEncode, v) | ||
if ok and | if ok and json2 then | ||
return | return json2 | ||
end | end | ||
return "" | return "" | ||