localfunctionranges(args)localvaluefunctioninrange(v)iftonumber(v)thenreturntonumber(v)==valueend-- simple number - just comparelocallp,a,b,rp=v:match('^([([]?)(.-)%.%.(.-)([)%]]?)$')-- a rangelocalna,nb=tonumber(a),tonumber(b)ifa~=''andnotna-- both a and b must be either empty or a valid numberorb~=''andnotnbornot(naornb)-- at least one of na, nb must be a numberthenerror(string.format('Bad parameter calling Range:iswitch: "%s" is not a number or valid range',v),0)returnfalseendlocalllok=notnaorna<valueorlp~='('andna==value-- left-limit-ok: no ll or ll < value or ll == value and not open rangelocalrlok=notnborvalue<nborrp~=')'andvalue==nb-- right-limit-ok: no rl or value < rl or value == rl and not open rangereturnllokandrlokendfunctionmatch(s)iftype(s)=='number'thenreturns==valueendlocalres=falses:gsub("%S+",function(c)res=resorinrange(c)end)returnresendvalue=tonumber(args.value)ifnotvaluethenerror('Range:iswitch: should have a numeric "value" parameter',0)endfork,vinpairs(args)doifk~='value'andk~='default'andmatch(k)thenreturnvendendreturnargs['default']or''endreturn{iswitch=function(frame)returnranges(frame.args)end,}