Revert back norm() to previous usage and add normDefault() overrided function that adds support to default to current frame's args
m (Allow passing in the current frame to norm() and still do proper processing) |
(Revert back norm() to previous usage and add normDefault() overrided function that adds support to default to current frame's args) |
||
end
-- If default is set to true (p.normDefault), the args will default to the current
-- A frame's arg table can never be nil since it is a metatable▼
-- frame's args if the parent frame is nil or its args are empty.
function p.norm( origArgs )▼
--
-- If default is set to false (p.norm), the parent frame args will always be used
-- or return an empty table if they do not exist.
local function norm( origArgs, default)
if type( origArgs ) ~= 'table' or origArgs == mw.getCurrentFrame() then
local frame = mw.getCurrentFrame()
local normedParent = {}
if parent ~= nil then
▲ -- A frame's arg table can never be nil since it is a metatable!
-- trim() also always at least returns an empty table
normedParent = trim( parent.args )
end
if not default then -- p.norm functionality
return normedParent
end
-- Table is empty if this is nil
if next( normedParent ) == nil then
return trim( frame.args ) -- normedCurrent
else
return normedParent
return trim( origArgs )
end
▲function p.norm( origArgs )
return norm( origArgs, false )
end
function p.normDefault( origArgs )
return norm( origArgs, true )
end
|