Module:Module link

From Uncyclopedia, the content-free encyclopedia
Jump to navigation Jump to search

-- implements {{ml}}
local ml = {} -- in this case ml serves as the package name
local getArgs = require('Module:Arguments').getArgs
local format = mw.ustring.format -- alternatively we can use string.format
local function err(msg) -- get errors
return format('<strong class="error">Error: %s</strong>', msg)
end
-- new function »
function ml.main(frame) -- this is for only templates
args = getArgs(frame)
return ml._main(args)
end

function ml._main(args) -- this is for modules only
name = args[1] or args.link
if name then
name = args[1] or args.link
elseif name == nil then
return err('parameter, value or both maybe missing, please inspect the codes carefully.') -- make new error
end
sandbox = mw.title.new(name .. '/sandbox')
if args.detectSandbox and args.detectSandbox == "off"
then
return format("[[:%s]]", name)
elseif sandbox and sandbox.exists then
return format("[[:%s]] ([[:%s|sandbox]])", name, sandbox.fullText)
else return format("[[:%s]]", name)
end
end
return ml