请输入您要查询的百科知识:

 

词条 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)

end

-- inspired by isitthursday.org-- returns whether or not it is Thursday,-- or some other day specified by the day argument.-- for example: {{#invoke:Sandbox/Gabe_Mitnick|thursday|day=Monday}}-- 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

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/11/14 17:23:40