(Note that I only just subscribed to the list this morning, so I can't properly quote or thread this because I don't have the original email to click reply on. This quote is therefore a copy and paste from <
http://lua-users.org/lists/lua-l/2015-02/msg00089.html>.)
Quote from Philipp Janda, Fri, 06 Feb 2015 08:47:05 +0100:
"I'd rather have it documented whether an iteration can be restarted at a certain point given only the iterator function, the state, and the current iteration variable. Because that's the other nice feature of the current iterator protocol. This is possible for e.g. `ipairs`, but not `string.gmatch` or `io.lines`."
I haven't tested io.lines, but this interactive session in Lua 5.1 works with string.gmatch:
> str = 't1t2t3t4t5'
> iter = str:gmatch('t%d')
> for match in iter do
>> print(match)
>> if match == 't3' then
>> break
>> end
>> end
t1
t2
t3
> print 'Doing other stuff...'
Doing other stuff...
> for match in iter do
>> print(match)
>> end
t4
t5
Notice how the second round resumes where the first left off, requiring just the iterator function (here, "iter"). Is this what you're looking for, or am I missing something?