Jump to content

Module:Arguments: Difference between revisions

return a table rather than a function, improve the comments
m>Mr. Stradivarius
(create argument-processing module)
 
m>Mr. Stradivarius
(return a table rather than a function, improve the comments)
Line 1: Line 1:
-- This module provides easy processing of arguments passed to Scribunto from #invoke.
-- This module provides easy processing of arguments passed to Scribunto from #invoke.
-- It is intended for use by other Lua modules, and should not be called from #invoke directly.


local function getArguments(frame, options)
local arguments = {}
 
function arguments.getArgs(frame, options)
options = type(options) == 'table' and options or {}
options = type(options) == 'table' and options or {}


-- Get the arguments from the frame object if available. If the frame object is not available, we are being called
-- from another Lua module or from the debug console, so assume arguments are passed directly in.
local fargs, pargs
local fargs, pargs
if frame == mw.getCurrentFrame() then
if frame == mw.getCurrentFrame() then
Line 31: Line 36:
end
end


-- Use a user-generated functions to tidy the values if specified.
local valueFunc = options.valueFunc
local valueFunc = options.valueFunc
if valueFunc then
if valueFunc then
Line 54: Line 60:
end
end


-- Set the order of precedence of frame args and parent args.
local firstArgs, secondArgs = fargs, pargs
local firstArgs, secondArgs = fargs, pargs
if options.parentFirst then
if options.parentFirst then
Line 59: Line 66:
end
end


-- Define metatable behaviour.
metatable.__index = function (t, key)
metatable.__index = function (t, key)
local val = metaArgs[key]
local val = metaArgs[key]
Line 99: Line 107:
end
end


return getArguments
return arguments
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.