Przejdź do zawartości

Moduł:Sandbox/Draco flavus/Test6

Z Wikiźródeł, wolnej biblioteki

Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:Sandbox/Draco flavus/Test6/opis

local p = {}

local escape_lua_pattern
do
  local matches =
  {
    ["^"] = "%^";
    ["$"] = "%$";
    ["("] = "%(";
    [")"] = "%)";
    ["%"] = "%%";
    ["."] = "%.";
    ["["] = "%[";
    ["]"] = "%]";
    ["*"] = "%*";
    ["+"] = "%+";
    ["-"] = "%-";
    ["?"] = "%?";
  }

  escape_lua_pattern = function(s)
    return (s:gsub(".", matches))
  end
end

local HighRomans = {
    { 1000, 'M' },
    { 900, 'CM' }, { 500, 'D' }, { 400, 'CD' }, { 100, 'C' },
    {  90, 'XC' }, {  50, 'L' }, {  40, 'XL' }, {  10, 'X' },
    {   9, 'IX' }, {   5, 'V' }, {   4, 'IV' }, {   1, 'I' }
}
local Romans = {
    { 1000, 'm' },
    { 900, 'cm' }, { 500, 'd' }, { 400, 'cd' }, { 100, 'c' },
    {  90, 'xc' }, {  50, 'l' }, {  40, 'xl' }, {  10, 'x' },
    {   9, 'ix' }, {   5, 'v' }, {   4, 'iv' }, {   1, 'i' }
}


local function ToHighRoman(num)
    local ret = {}
    for _, v in ipairs(Romans) do
        local val, letter = unpack(v)
        while num >= val do
            num = num - val
            table.insert(ret, letter)
        end
    end
    return table.concat(ret)
end

local function ToRoman(num)
    local ret = {}
    for _, v in ipairs(Romans) do
        local val, letter = unpack(v)
        while num >= val do
            num = num - val
            table.insert(ret, letter)
        end
    end
    return table.concat(ret)
end



function p.informat(frame)
	local strona = tonumber(frame.args[1])
	local aspekt = frame.args[2]
	local X=''
	local Y=''
	if aspekt == "normal" then
		X = tostring(strona)
	elseif aspekt == "roman" then
		X = ToRoman(strona)
	elseif aspekt == "highroman" then
		X = ToHighRoman(strona)
	elseif aspekt == "folio" then
		X = tostring((strona + strona % 2) / 2) .. ((strona % 2 == 0) and 'ᵛ' or 'ʳ')
	elseif aspekt == "folioroman" then
		X = ToRoman((strona + strona % 2) / 2) .. ((strona % 2 == 0) and 'ᵛ' or 'ʳ')
	elseif aspekt == "foliohighroman" then
		X = ToHighRoman((strona + strona % 2) / 2) .. ((strona % 2 == 0) and 'ᵛ' or 'ʳ')
	else
		X = aspekt
	end
	return X
end

return p