Module:Sandbox/Sarai Blanco Explained

-- 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

"" then msg= "Invalid title" return msg end local txt = ttlobj.text if ttlobj.exists then txt=txt.. " exists and " else txt=txt.. " does not exist and "end if ttlobj.redirectTarget then txt=txt.. "is a redirect
" else txt=txt.. "is not a redirect
" end return txtend

p.otra=function(frame) local fecha=frame.args.ff or "" local tipo=frame.args.format or "" if fecha

"" then local msg="Invalid entry" return msg.. "
" end local cir=0,ll ad=0 bc=0 bce=0 ce=0,lala lala=string.match(fecha,"BCE") if lala then bce=1 else lala=string.match(fecha,"BC") if lala then bc=1 end lala=string.match(fecha,"CE") if lala then ce=1 end end lala=string.match(fecha,"AD") if lala then ad=1 end

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 mes=(k/2)+0.5 else mes=k/2 end if mes~=0 then mesl=mesesp[mes] else buscm=1 end end local reco=fecha num1=0 numeros= hay="",pos pospala=kk,posnum1 for i=1,4 do num1 = string.match(reco, "(%d+)") or "" if i

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)

1 then pos=pos+1 end if string.len(num1)

2 then pos=pos+2 end if string.len(num1)

3 then pos=pos+3 end if string.len(num1)

4 then pos=pos+4 end if string.len(num1)

5 then pos=pos+5 end reco=string.sub(reco,pos) table.insert(numeros,num1) end end if mes

0 then if #numeros>1 then if #numeros

3 then for i=1,#numeros do numeros[i]=tonumber(numeros[i]) end mes=numeros[2] modo="iso" if numeros[1]" end anio=numeros[2] modo="year" end else if #numeros

1 then anio=numeros[1] modo="year" else local msg="Invalid entry" return msg.."
" end end else if #numeros

1 then if pospala

2 then dia=numeros[1] anio=numeros[2] if pospala" end end end

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]=29 else if anio2 % 100

0 then fechademes[2]=28 else if anio2% 4

0 then fechademes[2]=29 else fechademes[2]=28 end end end if mes~=0 and mes<13 and dia ~=0 and dia>fechademes[mes] then local msg="Invalid entry" return msg.."
" end if mes>12 then local msg="Invalid entry" return msg.."
" end local ss="" if modo

"" then local msg="Invalid entry" return msg.."
" end if tipo

"" then tipo=modo end if tipo

"dmy" then ss=dia.." "..mesesp[mes].." "..anio end if tipo

"mdy" then ss=mesesp[mes].." "..dia ..", "..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

"year" then ss=anio 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="circa "..ss end if ad

1 then ss=ss.." AD" end if bc

1 then ss=ss.." BC" end if bce

1 then ss=ss.." BCE" end if ce

1 then ss=ss.." CE" end ss=ss.."
" return ssend

return p