-- <nowiki>
-- Invokes global modules from
-- Syntax:
-- {{#invoke:Devmodule|main|<parameters>|#mod=<module-name>|#fun=<function-name>}}
local p = {}
local getArgs = require("Dev:Arguments").getArgs
local normalize = require("Dev:NormalizeModuleName")
local userError = require("Dev:User error")
local removeArgs = require("Dev:FrameTools").removeArgs
--% Entry point to use module
--@ frame (table) A scribunto frame
--: (string) The return content of the module 
function p.main(frame)
    local args = getArgs(frame)
    local moduleName = args["#mod"] or args["#modulename"]
    local functionName = args["#fun"] or args["#fname"] or "main"
    local success, _, invokedModule
    -- try to `normalize()` the given module name
    -- if this fails, then the user did not pass the right parameters
    success, _, moduleName = pcall(normalize, moduleName)
    if not success then
        return userError("no `#mod` parameter given " ..
                         "(should be the name of a module on dev.wikia)")
    -- try to `require()` the given module
    -- if this fails, then the user gave an incorrect module name
    success, invokedModule = pcall(require, "Dev:" .. moduleName)
    if not success then
        return userError("could not find a module called `" .. moduleName ..
                         "` on dev.wikia")
    -- make sure the module has a function called `functionName`
    -- if this fails, then the user gave an incorrect function name
    local func = invokedModule[functionName]
    if not func then
        return userError("that module does not have a function called `" ..
                         functionName .. "`")
    -- create a frame-like object, without the Devmodule-exclusive arguments
    local pseudoFrame = removeArgs(frame, "#mod", "#modulename", "#fun",
    -- call the function
    -- any errors from the function itself will be passed to the user
    return func(pseudoFrame)
return p
-- </nowiki>
-- (Add categories here.)

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.