Zum Inhalt springen

Modul:Arguments: Unterschied zwischen den Versionen

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


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


return getArguments
return arguments
Anonymer Benutzer