Module:Sandbox/Janeccerek

--Jan Nowosielski Google Code-in 2017, Introduction in Lua to Wikipedia --[Lua task #3] Create your own Lua module on English Wikipedia local p = {} -- p stands for package

function p.hello( frame ) return "Hello, world!" end

p.Hi = function(frame) strName = frame.args.name or "Jimbo" return "Hello from Lua to my friend " .. strName .. ". " end

function p.temperature(frame) cel = frame.args.celsius or 0 fah = cel*9/5+32 val_cel = tonumber(cel) msg = "" ..cel.. " degrees Celsius is " ..fah.. " degrees Fahrenheit." if 9<val_cel then msg = msg.." It is warm. " else msg = msg.." It is cold. " end return msg end

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

p.mum = function(frame) local family = {"Dad", "Mum", "Uncle Stan", "Aunty Elsie", "Brian", "Grandpa Sam", "Granny Natalie", "Austin"} local msg = "" for i = 1, #family do msg = msg .. "Hello " .. family[i] .. " "	end return msg end

p.langnames = function( frame ) local langs = mw.language.fetchLanguageNames local langlist = "" local count = 0 for key, value in pairs( langs ) do langlist = langlist .. key .. " - " .. value .. " "		count = count + 1 end return langlist .. " = " .. count .. " languages" end

p.pageinfo = function( frame ) local title = frame.args.title local titleobj = mw.title.new(title) local msg = "" if titleobj.exists then msg = msg .. title .. " exists " if titleobj.isRedirect then msg = msg .. "and is a redirect. " else msg = msg .. "and is not a redirect. " end else msg = msg .. title .. " does not exist and is not a redirect. " end return msg end p.test = function( frame ) local test = frame.args.test if string.find(' ', test) ~= 0 then msg = "!!!!!" else msg = "////" end return msg end

return p