Module:Sandbox/Gabe Mitnick

-- Gabe Mitnick Google Code-in 2017, Introduction to Lua in Wikipedia

local p = {} -- p stands for package

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

-- inspired by isitthursday.org -- returns whether or not it is Thursday, -- or some other day specified by the day argument. -- for example: -- os.date isn't accurate for the user's timezone, but for some other timezone. p.thursday = function(frame) weekday = frame.args.day or "Thursday" if os.date("%A") == weekday then return "it is " .. weekday else return "it's not " .. weekday end end

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

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

-- Displays a mathematical "times-table" -- The number base for the times-table is passed as parameter "num" -- If no parameter or a blank parameter or a value less than 2 is passed, use 2 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", "Grandma", "Cinnamon", "Beth"} 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) if (frame.args.title == nil) then error("Please provide an artictle title") else local titleObj = mw.title.new(frame.args.title) local returnVal = frame.args.title if (titleObj.exists) then returnVal = returnVal .. " exists and is " else returnVal = returnVal .. " does not exist and is " end if (titleObj.isRedirect) then returnVal = returnVal .. "a redirect. " else returnVal = returnVal .. "not a redirect. " end return returnVal end end return p