Modulo:Sandbox/M.casanova/Prova2: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
mNessun oggetto della modifica
Omega Bot (discussione | contributi)
m Bot: rimuovo no globals obsoleto
 
(44 versioni intermedie di un altro utente non mostrate)
Riga 1:
require('Module:No globalsstrict')
local getArgs = require('Module:Arguments').getArgs
 
Riga 5:
local txt = {}
 
local function aggerrhandler(...msg)
local cat = mw.title.getCurrentTitle().namespace == 0 and errorCategory or ''
local args = {...}
return string.format('<span class="error">%s</span>%s', msg, cat)
for _, s in ipairs(args) do
table.insert(txt, s)
end
end
 
Riga 19 ⟶ 17:
local function semplifica(t)
local d
if (t[1] >== t[2]0) then d=gcd(t[1],t[2]) else d=gcd(t[2],t[1]) end
return a[1]t
end
if value(t[1] =>= nilt[2]) then
d=gcd(t[1],t[2])
else
d=gcd(t[2],t[1])
end
return {t[1]/d,t[2]/d}
end
Riga 28 ⟶ 33:
 
local function mostra(a)
if (a[21] == 10) then
error('Errore nei dati')
return a[1]
else
if type(key)a[2] == "number"1) then
return '<sup>'..a[1]..'</sup>⁄<sub>'..a[2]..'</sub>'
return valuea[1]
else
return '<sup>'..a[1]..'</sup>⁄<sub>'..a[2]..'</sub>'
end
end
end
 
function p.main_main(frameargs)
local args = getArgs(frame, {
valueFunc = function (key, value)
if type(key) == "number" then
if value == nil then
return nil
else
value = mw.text.trim(value)
end
else
if value == '' then return nil end
end
return value
end
})
local uni = {}
local n = 1
local valore = 0false
local note = 0false
while (args['nome'..n]) do
uni[n] = {
uni[n] = { nome = args['nome'..n], valore = args['valore'..n] or -1, unita = args['unit'..n] or '', nota = args['nota'..n], numero = { tonumber(args['num'..n]) or 1, tonumber(args['den'..n]) or 1}, num = {1,1} }
nome = args['nome'..n],
if (uni[n].nota ~= '') then note = 1 end
valore = args['valore'..n] or -1,
if (uni[n].valore ~= -1) then valore = 1 end
unita = args['unit'..n] or '',
nota = args['nota'..n] or '',
numero = { tonumber(args['num'..n]) or 0, tonumber(args['den'..n]) or 1},
num = {1,1}
}
if (uni[n].nota ~= '') then note = 1true end
if (uni[n].valore ~= -1) then valore = 1true end
uni[n].numero = semplifica(uni[n].numero)
n = n+1
end
n = n-1
local bTabella = mw.html.create('table')
 
agg :addClass('{| class="wikitable" style="'):css({['text-align:center"\n!colspan']=',n,'|Nomecenter'})
local bRiga = mw.html.create('tr')
if (valore == 1) then agg('!!colspan=2|Valore') end
bRiga:node(mw.html.create('th'):attr({['colspan']=n}):wikitext('Nome'))
if (note == 1) then agg(' !!Note') end
if (valore == true) then
bRiga:node(mw.html.create('th'):attr({['colspan']=2}):wikitext('Valore'))
end
if (note == 1true) then agg(' !!Note') end
bRiga:node(mw.html.create('th'):wikitext('Note'))
end
bTabella:node(bRiga)
for i, v in pairs(uni) do
local bRiga = mw.html.create('tr')
agg('\n|-\n|')
for j=1,i-1 do
uni[j].num = moltiplica(uni[j].num,v.numero)
aggbRiga:node(mw.html.create('style="backgroundtd'):css('background','#eee"|',):wikitext(mostra(uni[j].num),' ||'))
end
aggbRiga:node(mw.html.create('td'):attr({['colspan=',]=n-i+1,[' align']='left|',}):wikitext(v.nome))
if (valore == 1true) then
if (v.valore == -1) then
bRiga:node(mw.html.create('td'):attr({['colspan']=2}))
agg('|| || ')
else
bRiga:node(mw.html.create('td'):wikitext(v.valore))
agg('||align=right|',v.valore,' ||',v.unita)
bRiga:node(mw.html.create('td'):wikitext(v.unita))
end
end
if (note == 1true) then
if (v.nota == '') then
bRiga:node(mw.html.create('td'):wikitext(''))
agg(' ||')
else
aggbRiga:node(mw.html.create('td'):attr({[' ||align']='left|'}):wikitext('<small>',..v.nota,..'</small>'))
end
end
bTabella:node(bRiga)
end
return tostring(bTabella)
agg('\n|}')
end
return table.concat(txt)
 
function p.main(frame)
local args = getArgs(frame, {
valueFunc = function (key, value)
if type(key) == "number" then
if value == nil then
return nil
else
value = mw.text.trim(value)
end
else
if value == '' then return nil end
end
return value
end
})
return tablep.concat_main(txtargs)
end