Modulo:MultiBand: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Nuova pagina: -- modulo per gestire l'omonimo template -- la gestione dei parametri con numeri progressivi prende spunto da Modulo:Tracce local args = {} local maxInterval = 0 loca...
 
m modulo no globals obsoleto
 
(10 versioni intermedie di 2 utenti non mostrate)
Riga 1:
--[[
-- modulo per gestire l'omonimo template
* Modulo a supporto del template MultiBand.
-- la gestione dei parametri con numeri progressivi prende spunto da Modulo:Tracce
]]--
 
require('strict')
local args = {}
local maxInterval = 0
 
local functionp getValue(param,= year){}
 
result = ""
-- Dato un unico parametro posizionale che può valere "nome" o "imm"
for i=1,maxInterval do
-- e un parent arg con nome "anno", itera i parent arg "annoN" e restituisce
currentYear = args["anno" .. i]
-- il relativo nomeN o immN se l'anno richiesto è >= di annoN,
if currentYear > year then break end
-- altrimenti l'ultimo valore precedente noto.
temp = args[param .. i]
function p.get(frame)
if temp ~=nil then
local pframepargs = frame:getParent().args
result = args[param .. i]
local reqAnno = tonumber(pargs.anno) or (tonumber(os.date('%Y'))+1)
local ret
 
for in = 1,maxInterval 50 do
local anno = tonumber(pargs['anno' .. n])
if temp ~=nilanno then
if reqAnno >= anno then
ret = pargs[frame.args[1] .. n] or ret
end
else
break
end
end
return result
end
 
return resultret
function p.get(frame)
local pframe = frame:getParent()
for k, v in pairs( pframe.args ) do
-- mappo gli argomenti del template
if v ~=nil then args[k] = v end
-- cerco l'intervallo più recente in base al numero più alto fra "nomeN", "voceN" e "immN"
num = string.match(k, "(?:nome|voce|imm)(%d+)$")
if num then
if tonumber(num) > maxInterval then
maxInterval = num
end
end
end
local year = args["anno"]
if year == nil then year = getValue("anno", maxInterval) end
return "|nome = " .. getValue("nome", year)
.. "|voce = " .. getValue("voce", year)
.. "|imm = " .. getValue("imm", year)
end