-- Sarai Blanco Google Code-in, Introduction to Lua in Wikipedia-- Sarai Blanco Google Code-in, Working with modules
local p =
function p.hello(frame) return "hello"end
p.Hi = function(frame) strName = frame.args.name or "Jimbo" return "Hello from Lua to my friend " .. strName .. ".
"end
p.temperature = function(frame) cel = tonumber(frame.args.celsius) or 0 fah = ((cel*9)/5)+32 msg = cel .. " degrees Celsius is " .. fah .. " degrees Fahrenheit." if cel>9 then msg=msg.. " It is warm.
" else msg=msg.. " It is cold.
" end return msgend
--Task 4
p.times = function(frame) local num = tonumber(frame.args.num) or 2 local out = num .. " times table
" for i = 1, 12 do out = out .. num.." times ".. i .. " equals " ..(i * num) .. "
" end return outend
p.mum = function(frame) local family = local msg = "" for i = 1, #family do msg = msg .. "Hello " .. family[i] .. "
" end return msgend
p.sentence = function(frame) local str = frame.args.words or "" local out = string.upper(string.sub(str, 1, 1)) local out = out.. string.sub (str, 2) return outend
p.unpackdate = function(frame) local dmydate = frame.args.dmydate or "" local day, month, year = string.match(dmydate, "(%d+) (%w+) (%d+)") return "Year = " .. year .. "
Day = " .. day .. "
Month = " .. monthend
p.langnames = function(frame) local langlist = mw.language.fetchLanguageNames local langs = "" local count = 0 for k, v in pairs(langlist) do langs = langs .. k .. " - " .. v .. "
" count = count + 1 end return langs .. "
= " .. count .. " languages"end
p.fallbacks = function(frame) local langcode = frame.args.langcode or "" local langlist = mw.language.getFallbacksFor(langcode) local langs = "" for k, v in pairs(langlist) do langs = langs .. k .. " - " .. v .. "
" end return langs end
p.pagename = function(frame) local ttl = frame.args.title local ttlobj = mw.title.new(ttl) local txt = ttlobj.text return txtend
p.pageinfo = function(frame) local ttl = frame.args.title or "" local ttlobj = mw.title.new(ttl) or "" if ttlobj
p.otra=function(frame) local fecha=frame.args.ff or "" local tipo=frame.args.format or "" if fecha
ll=string.match(fecha,"uncertain") if ll then cir=1 end ll=string.match(fecha,"around") if ll then cir=1 end local mesesp = local months = local fechademes = local k=0,g modo="",kk for i=1, #months do g=string.find(fecha,months[i]) or 0 if g~=0 then k=i kk=g end end local mes=0,mesl,anio,dia if k~=0 then if k%2
1 then hay = string.match(reco, "(%w+)") or "" posnum1=string.find(reco,num1) end if num1~="" then pos=string.find(reco,num1) if string.len(num1)
2 then pos=pos+2 end if string.len(num1)
4 then pos=pos+4 end if string.len(num1)
0 then if #numeros>1 then if #numeros
1 then anio=numeros[1] modo="year" else local msg="Invalid entry" return msg.."
" end end else if #numeros
2 then dia=numeros[1] anio=numeros[2] if pospala
anio=tonumber(anio) or 0 dia=tonumber(dia) or 0 mes=tonumber(mes) or 0 local anio2=anio if anio2<100 then anio2=anio2+2000 end if anio2 % 1000
0 then fechademes[2]=28 else if anio2% 4
"" then local msg="Invalid entry" return msg.."
" end if tipo
"dmy" then ss=dia.." "..mesesp[mes].." "..anio end if tipo
"iso" then if dia<10 then dia="0"..dia end if mes<10 then mes="0"..mes end ss=anio.."-"..mes.."-"..dia end if tipo
"month and year" then if dia~=0 then ss=dia.." "..mesesp[mes] else ss=mesesp[mes].." "..anio end end if cir
1 then ss=ss.." AD" end if bc
1 then ss=ss.." BCE" end if ce
return p