Module:Switch

--Replaces the ineficient parser function -- Demo module --Syntax - where option is any string to match and caseX any key-value pairs --Syntax2  -> bcd -- local frame = {args = { '1',['#default']=8, 5 },getParent = function local pArgs = {'1',['src']=8, 5 }  return { args = pArgs } end } mw.log('') local p = {}

function p.main(frame) local tArgLang = frame.args return p.switch(tArgLang) end

function p.switch(tArgs) if tArgs then if tArgs[1] and tArgs[1] ~= "" then local sCase = (tArgs[1] or "") sCase = mw.text.trim(sCase) if tonumber(sCase) then sCase = tonumber(sCase)+1 end if not(tArgs[sCase]) then sCase = "#default" if tonumber(sCase) and sCase<2   then return "" end end return mw.getCurrentFrame:preprocess(tArgs[sCase] or "") elseif (tArgs["#default"]) then return tArgs["#default"] else return "" end end end

return p