Difference between revisions of "Module:Switch"

From Sudo Room
Jump to navigation Jump to search
(creates module)
 
(No difference)

Latest revision as of 11:24, 19 May 2014

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

Script error: Lua error: Cannot create process: proc_open(/dev/null): failed to open stream: Operation not permitted

s = {};

function s.switch( frame )
    local list = frame.args[1] or frame.args.list;
    local case = frame.args[2] or frame.args.case;
    local default = frame.args[3] or frame.args.default;
    local result;
    
    list = mw.loadData( 'Module:' .. list );
    
    if case ~= nil then
        if tonumber( case ) ~= nil then
            case = tonumber( case );
        end
        
        result = list[ case ];
    else
        return frame:expandTemplate{ title="FormattingError", args = {"No selection specified"} };
    end
    
    if result == nil then
        if default ~= nil then
            return default;
        else
            result = list[ '#default' ];
            if result == nil then 
                return frame:expandTemplate{ title="FormattingError", args= {"Selection not found"} };
            end
        end
    end

    return result;
end

return s;