Module:Arguments/doc: Difference between revisions

From Mariopedia, a wiki on Mario, Yoshi, Wario, Donkey Kong, Super Smash Bros., and more!
Jump to navigationJump to search
add wrapper function info
(start the documentation)
 
(add wrapper function info)
Line 32:
local getArgs = require('Module:Arguments').getArgs
local p = {}
 
function p.main(frame)
local args = getArgs(frame)
return p._main(args)
end
 
function p._main(args)
Line 37 ⟶ 42:
end
 
return p
function p.main(frame)
</source>
local args = getArgs(frame)
 
return p._main(args)
If you want multiple functions to use the arguments, and you also want them to be accessible from #invoke, you can use a wrapper function.
 
<source lang="lua">
local getArgs = require('Module:Arguments').getArgs
 
local function makeInvokeFunc(funcName)
return function (frame)
local args = getArgs(frame)
return p[funcName](args)
end
end
 
local p = {}
 
p.func1 = makeInvokeFunc('_func1')
 
function p._func1(args)
-- Code for the first function goes here.
end
 
p.func2 = makeInvokeFunc('_func2')
 
function p._func2(args)
-- Code for the second function goes here.
end
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu