lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, Jun 08, 2011 at 09:37:15AM +0200, steve donovan wrote:
> On Wed, Jun 8, 2011 at 12:46 AM, Igor Medeiros <igorosbergster@gmail.com> wrote:
> > (systemScreen([1 .. 9])|systemAudio([1 .. 9]))
> 
> OK, your problem is that Lua patterns do not do alternatives like
> this. So you will have to split the match into two patterns:
> 

If you do it this way:

match = function (s,t,init)
  if type(t)=="table" then 
    for _,pattern in ipairs(t) do
      if string.match(s,pattern,init) then 
        return string.match(s,pattern,init) 
        end
      end
      return    
    else return string.match(s,t,init) 
    end
  end

then match(s,t,init) behaves like string.match, but also allows

match(s,{"systemScreen\([1-9]\)","systemAudio\([1-9]\)"})

(Actually, it would be nice if the the definition of a pattern
could be extended to allow table arguments in this way to all
string functions.  This is not a non-suggestion!)

Dirk