Modulo:Sandbox/M.casanova/Prova2: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
mNessun oggetto della modifica |
m Bot: rimuovo no globals obsoleto |
||
(44 versioni intermedie di un altro utente non mostrate) | |||
Riga 1:
require('
local getArgs = require('Module:Arguments').getArgs
Riga 5:
local txt = {}
local function
local cat = mw.title.getCurrentTitle().namespace == 0 and errorCategory or ''
return string.format('<span class="error">%s</span>%s', msg, cat)
end▼
end
Riga 19 ⟶ 17:
local function semplifica(t)
local d
if (t[1]
d=gcd(t[1],t[2])
d=gcd(t[2],t[1])
end
return {t[1]/d,t[2]/d}
end
Riga 28 ⟶ 33:
local function mostra(a)
if (a[
error('Errore nei dati')
▲ return a[1]
else
return '<sup>'..a[1]..'</sup>⁄<sub>'..a[2]..'</sub>'▼
▲ return '<sup>'..a[1]..'</sup>⁄<sub>'..a[2]..'</sub>'
end
end
function p.
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▼
▲ return value
▲ end
})▼
local uni = {}
local n = 1
local valore =
local note =
while (args['nome'..n]) do
uni[n] = {
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}
}
uni[n].numero = semplifica(uni[n].numero)
n = n+1
end
n = n-1
local bTabella = mw.html.create('table')
local bRiga = mw.html.create('tr')
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
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')
for j=1,i-1 do
uni[j].num = moltiplica(uni[j].num,v.numero)
end
if (valore ==
if (v.valore == -1) then
bRiga:node(mw.html.create('td'):attr({['colspan']=2}))
else
bRiga:node(mw.html.create('td'):wikitext(v.valore))
bRiga:node(mw.html.create('td'):wikitext(v.unita))
end
end
if (note ==
if (v.nota == '') then
bRiga:node(mw.html.create('td'):wikitext(''))
else
end
end
bTabella:node(bRiga)
end
return tostring(bTabella)
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
▲ })
end
|