lua-users home
lua-l archive

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


On Fri, 8 Feb 2002, Bansard Stephane wrote:

> Could anyone tell me how to write a function to create a string array
> (like the %w notation in ruby or Perl) ? (or redirect me to the right place in
> the doc!)
>  ex: f(a, b, c) would return {"a", "b", "c"}

You can write something like «f'a b c'», and then it is easy to code `f':

  function f (s)
    local res = {}
    gsub(s, '(%w+)', function (w) tinsert(res, w) end)
    return res
  end

(Actually, it is a "split" function...)

-- Roberto