Module:Switch

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;