Difference between revisions of "Module:Arguments"

Jump to navigation Jump to search
265 bytes added ,  21:00, 12 January 2014
Fix __pairs and __ipairs functions to handle the nil marker
>Mr. Stradivarius
m (Changed protection level of Module:Arguments: High-risk Lua module ([Edit=Allow only template editors and admins] (indefinite) [Move=Allow only template editors and admins] (indefinite)))
>Anomie
(Fix __pairs and __ipairs functions to handle the nil marker)
Line 169: Line 169:
metatable.doneIpairs = true
metatable.doneIpairs = true
end
end
return pairs(metaArgs)
return function ( t, k )
local nk, val = next( metaArgs, k )
if val == nilArg then
val = nil
end
return nk, val
end
end
end


Line 177: Line 183:
metatable.doneIpairs = true
metatable.doneIpairs = true
end
end
return ipairs(metaArgs)
return function ( t, i )
local val = metaArgs[i + 1]
if val == nil then
return nil
elseif val == nilArg then
val = nil
end
return i + 1, val
end, nil, 0
end
end


Anonymous user

Navigation menu