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

мНет описания правки
Нет описания правки
Строка 44: Строка 44:
         return tostring(v)
         return tostring(v)
     elseif t == "table" then
     elseif t == "table" then
         local max = 0
         local ok, json = pcall(mw.text.jsonEncode, v)
        local hasNonNumber = false
         if ok and json then
        for k in pairs(v) do
             return json
            if type(k) ~= "number" then
                hasNonNumber = true
                break
            else
                if k > max then max = k end
            end
        end
         if not hasNonNumber and max > 0 then
            local out = {}
            for i = 1, max do
                out[#out + 1] = format_value(v[i])
            end
             return table.concat(out, ", ")
        else
            local out = {}
            for k, val in pairs(v) do
                out[#out + 1] = tostring(k) .. ": " .. format_value(val)
            end
            return table.concat(out, ", ")
         end
         end
        return ""
     else
     else
         return tostring(v)
         return tostring(v)