Module:Arguments: Difference between revisions
m
Reverted edits by Paladox2017 (talk) to last revision by Quiddity (WMF)
(Import updated version from en.wikipedia.org) |
m (Reverted edits by Paladox2017 (talk) to last revision by Quiddity (WMF)) |
||
Line 47:
return val
end
function arguments.getArgs(frame, options)
Line 60 ⟶ 53:
frame = frame or {}
options = options or {}
if options.translate[k] ~= k then▼
else▼
end▼
--[[
Line 114 ⟶ 82:
local title = parent:getTitle():gsub('/sandbox$', '')
local found = false
if
found = true▼
for _,v in pairs(options.wrappers) do
if
found = true
break
end
end
▲ found = true
end
-- We test for false specifically here so that nil (the default) acts like true.
if found or options.frameOnly == false then
Line 149 ⟶ 117:
luaArgs = frame
end
-- Set the order of precedence of the argument tables. If the variables are
-- nil, nothing will be added to the table, which is how we avoid clashes
-- between the frame/parent args and the Lua args.
local argTables = {fargs}
argTables[#argTables + 1] = pargs
Line 197 ⟶ 165:
setmetatable(args, metatable)
local function mergeArgs(iterator, tables)
--[[
-- Accepts multiple tables as input and merges their keys and values
-- into one table using the specified iterator. If a value is already
-- present it is not overwritten; tables listed earlier have precedence.
-- We are also memoizing nil values, but those values can be
-- overwritten.
--]]
for _, t in ipairs(tables) do
for key, val in
if metaArgs[key] == nil
local tidiedVal = tidyVal(key, val)
if tidiedVal == nil then
nilArgs[key] =
else
metaArgs[key] = tidiedVal
Line 242 ⟶ 211:
-- must be nil.
--]]
local val = metaArgs[key]
if val ~= nil then
Line 253 ⟶ 219:
for _, argTable in ipairs(argTables) do
local argTableVal = tidyVal(key, argTable[key])
if argTableVal
metaArgs[key] = argTableVal
return argTableVal
end
end
▲ nilArgs[key] = 'h'
return nil
end
Line 265 ⟶ 232:
-- This function is called when a module tries to add a new value to the
-- args table, or tries to change an existing value.
if options.readOnly then
error(
Line 291 ⟶ 255:
--]]
metaArgs[key] = nil
nilArgs[key] =
else
metaArgs[key] = val
end
end
Line 318 ⟶ 264:
-- Called when pairs is run on the args table.
if not metatable.donePairs then
mergeArgs(pairs, argTables)
metatable.donePairs = true
metatable.doneIpairs = true
end
return
end
-- Called when ipairs is run on the args table.▼
if not metatable.doneIpairs then
mergeArgs(ipairs, argTables)
metatable.doneIpairs = true
end
return ipairs(metaArgs)
▲ -- Called when ipairs is run on the args table.
end
|