Difference between revisions of "Module:Utils"

From Team Fortress Wiki
Jump to: navigation, search
m (Lowercase all parameter names)
m (Undo edit by Moussekateer (Talk) (1519622))
Line 23: Line 23:
 
     for k, v in pairs(origArgs) do
 
     for k, v in pairs(origArgs) do
 
         if v ~= '' then
 
         if v ~= '' then
            -- parameter names should be case-insensitive
+
             args[k] = v
             args[string.lower(k)] = v
 
 
         end
 
         end
 
     end
 
     end

Revision as of 15:56, 27 November 2013

Documentation for this module may be created at Module:Utils/doc

local util = {}

function util.get_args(frame)
    local origArgs
    if frame == mw.getCurrentFrame() then
        -- We're being called via #invoke. If the invoking template passed any args, use
        -- them. Otherwise, use the args that were passed into the template.
        origArgs = frame:getParent().args
        for k, v in pairs(frame.args) do
            origArgs = frame.args
            break
        end
    else
        -- We're being called from another module or from the debug console, so assume
        -- the args are passed in directly.
        origArgs = frame
    end
 
    -- ParserFunctions considers the empty string to be false, so to preserve the previous 
    -- behavior of the template, change any empty arguments to nil, so Lua will consider
    -- them false too.
    local args = {}
    for k, v in pairs(origArgs) do
        if v ~= '' then
            args[k] = v
        end
    end
    return args
end

return util