Module:Arguments: Difference between revisions
m
tweak one of the comments and make some beautification fixes, now that this is in the job queue
m>Anomie (Fix __pairs and __ipairs functions to handle the nil marker) |
m>Mr. Stradivarius m (tweak one of the comments and make some beautification fixes, now that this is in the job queue) |
||
Line 99: | Line 99: | ||
local function mergeArgs(iterator, tables) | local function mergeArgs(iterator, tables) | ||
-- Accepts multiple tables as input and merges their keys and values into one table using the specified iterator. | -- 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 | -- 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. | -- We are also memoizing nil values, but those values can be overwritten. | ||
for _, t in ipairs(tables) do | for _, t in ipairs(tables) do | ||
Line 169: | Line 169: | ||
metatable.doneIpairs = true | metatable.doneIpairs = true | ||
end | end | ||
return function ( t, k ) | return function (t, k) | ||
local nk, val = next( metaArgs, k ) | local nk, val = next(metaArgs, k) | ||
if val == nilArg then | if val == nilArg then | ||
val = nil | val = nil | ||
Line 183: | Line 183: | ||
metatable.doneIpairs = true | metatable.doneIpairs = true | ||
end | end | ||
return function ( t, i ) | return function (t, i) | ||
local val = metaArgs[i + 1] | local val = metaArgs[i + 1] | ||
if val == nil then | if val == nil then |