Module:Switch
From Fallen London Wiki (Staging)
Documentation for this module may be created at Module:Switch/doc
--Replaces the inneficient {{#switch }} parser function
--Syntax - {{#invoke:switch|main|var=option|caseX=3|abc=z}} where option is any string to match
--and caseX any key-value pairs
--Syntax2 {{#invoke:switch|main|2|abc|bcd|222}} -> bcd
local p = {}
function p.main(frame)
local tArgLang = frame.args
return p.switch(tArgLang)
end
function p.switch(tArgs)
if tArgs and tArgs[1] then
local sCase = tArgs[1]
if tonumber(sCase) then
sCase = tonumber(sCase)+1
end
return mw.getCurrentFrame():preprocess(tArgs[sCase] or "")
end
end
return p