"ماڈیول:Arguments" کے نسخوں کے درمیان فرق

create argument-processing module
 
return a table rather than a function, improve the comments
سطر 1: سطر 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
سطر 31: سطر 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
سطر 54: سطر 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
سطر 59: سطر 66:
end
end


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


return getArguments
return arguments