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

мНет описания правки
мНет описания правки
Строка 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, json = pcall(mw.text.jsonEncode, v)
         local ok, json2 = pcall(mw.text.jsonEncode, v)
         if ok and json then
         if ok and json2 then
             return json
             return json2
         end
         end
         return ""
         return ""