Search code examples
performancelualua-patterns

Lua - string.gmatch iterator - does it search every iteration?


Does gmatch iterator finds all occurences immediately after it was called or does it try to find new occurence each iteration?

for elem in string.gmatch(s, pattern) do
    ...
end

It's important because it will be used a lot in my program, so if string.gmatch just tries to find next occurence each iteration, it will be much more friendlier to performance.


Solution

  • string.gmatch produces an iterator which finds the next match at each iteration.