Module:Example

local p = {}

-- Most basic example: p.helloWorld = function return 'Hello, world!' end

-- Basic example with args: p.helloName = function( f ) local args = f.args return 'Hello, ' .. args.name .. '!' end

-- Basic example with parent args: -- Then use in a template: p.parentHello = function( f ) local args = f:getParent.args return 'Hello, ' .. args.name .. '!' end

-- Basic example of using both direct args and parent args -- for separate purposes -- -- p.makeConfigGreeting = function( f ) local args = f.args local parentArgs = f:getParent.args return args.greeting .. ', ' .. parentArgs.name .. '!' end

-- Example of a script which can use either direct args -- or parent args, but not both at the same time p.makeFlexableGreeting = function( f ) local args = f.args local parentArgs = f:getParent.args for _ in pairs( parentArgs ) do		args = parentArgs break end return args.greeting .. ', ' .. args.name .. '!' end

-- Basic example of using both direct args and -- parent args at the same time p.makeFlexableConfigGreeting = function( f ) local args = f.args local parentArgs = f:getParent.args local greeting = parentArgs.greeting or args.greeting local name = parentArgs.name or args.name return greeting .. ', ' .. name .. '!' end

-- Example of merging both direct args and parent args -- to make one table, allowing both sets of args to be used p.makeMergedGreeting = function( f ) local directArgs = f.args local parentArgs = f:getParent.args local args = {} for _, argType in ipairs{ directArgs, parentArgs } do		for key, val in pairs( argType ) do			args[key] = val end end return args.greeting .. ', ' .. args.name .. '!' end

-- Basic example of requiring another module, and accessing its globals p.acquireGlobals = function( f ) require( 'Module:Example/AcquireGlobals' ) return constructHello( name ) end

-- More recommended example of requiring a module -- This time it returns a table, with a string and function in it p.requiredHello = function( f ) local helloModule = require( 'Module:Example/Hello' ) local name = helloModule.name return helloModule.constructHello( name ) end

-- Recommended example of requiring a module which can be invoked as well -- It returns a table again, but this time we pass a table with our args back p.requiredInvoke = function( f ) local helloModule = require( 'Module:Example/FlexableHello' ) return helloModule.constructHello{ name = 'John Doe' } end

-- Basic example of accessing data p.bigData = function( f ) local data = mw.loadData( 'Module:Example/Data' ) return 'Hello, ' .. data.name .. '!' end

return p