lua-users home
lua-l archive

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

Javier Guerra wrote:
On 1/3/08, Duncan Cross <> wrote:
Here's a first attempt at a splitting gmatch:

here's one of the best... this is a recurring thread!

It seems, Rici's function can be further simplified by not passing 'self' around:

function string:split(pat)
  local st, g = 1, self:gmatch("()("..pat..")")
  local function getter(segs, seps, sep, cap1, ...)
    st = sep and seps + #sep
    return self:sub(segs, (seps or 0) - 1), cap1 or sep, ...
  return function()
    if st then return getter(st, g()) end