Module:Sandbox
Jump to navigation
Jump to search
Assumption: lua modules can only be #invoke'd if they reside within the Module namespace.
Assertion: littering said namespace with random test pages would be an inconvenient for everyone.
Conclusion: Shove your testing and unfinished projects into Module:Sandbox/YourUsername or Module:Sandbox/YourUsername/Whatever to allow your tests to function while avoiding making a mess.
-- define a table which will contain all the externally invokable functions
local p = {}
-- naming the function directly as a property of the table is one way
function p.print1(frame)
return "This prints."
end
-- assigning it is another way
p.print2 = function(frame)
return "This prints."
end
--[[
if you want things to be accessible to functions of your module
but dont need them accessible from #invoke, they dont need to
be properties of the returned table
]]--
local greetings = {"Hello", "Hiya", "Greetings", "Acknowledging", "Hey"}
function randomEntry(t)
return t[math.random(#t)]
end
function randomGreeting()
return randomEntry(greetings)
end
-- -- --
function p.hello(frame)
return randomGreeting() .. " " .. frame.args.name or frame.args[1] or frame:getParent().args.name or frame:getParent().args[1] or "there" .. "!"
end
-- expose your table of functions for #invoke
return p