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

Материал из Space Station 14 Вики
Новая страница: «local p = {} local getArgs = require('Module:Arguments').getArgs function p.main(frame) local args = getArgs(frame, { removeBlanks = false }) local value = args[1] if not value then return "" end local num = tonumber(value) local color = num and (num > 0 and "good" or "bad") or "text" local amt = num and ((num > 0) and ("+" .. num) or tostring(num)) or tostring(value) return frame:preprocess(string.format("{{цвет|t...»
 
Нет описания правки
 
Строка 9: Строка 9:
     end
     end


    local invert = args.invert
     local num = tonumber(value)
     local num = tonumber(value)
     local color = num and (num > 0 and "good" or "bad") or "text"
 
     local color
    if num then
        if invert then
            color = num > 0 and "bad" or "good"
        else
            color = num > 0 and "good" or "bad"
        end
    else
        color = "text"
    end
 
     local amt = num and ((num > 0) and ("+" .. num) or tostring(num)) or tostring(value)
     local amt = num and ((num > 0) and ("+" .. num) or tostring(num)) or tostring(value)



Текущая версия от 05:26, 14 марта 2026

Для документации этого модуля может быть создана страница Модуль:SignedNumber/doc

local p = {}
local getArgs = require('Module:Arguments').getArgs

function p.main(frame)
	local args = getArgs(frame, { removeBlanks = false })
    local value = args[1]
    if not value then
        return ""
    end

    local invert = args.invert
    local num = tonumber(value)

    local color
    if num then
        if invert then
            color = num > 0 and "bad" or "good"
        else
            color = num > 0 and "good" or "bad"
        end
    else
        color = "text"
    end

    local amt = num and ((num > 0) and ("+" .. num) or tostring(num)) or tostring(value)

    return frame:preprocess(string.format("{{цвет|text|%s|c='''%s'''}}", color, amt))
end

return p