gopher-lua
gopher-lua copied to clipboard
Return a closure without arguments in gfind
Fixes #462.
In https://www.lua.org/manual/5.1/manual.html#pdf-string.gmatch is written for gmatch
:
Returns an iterator function that, each time it is called, returns the next captures from pattern over string s. If pattern specifies no captures, then the whole match is produced in each call.
For gfind
is written (which is a deprecated name for gmatch
):
The gfind function fits perfectly with the generic for loop. It returns a function that iterates on all occurrences of a pattern in a string.
Before this change only first sentence worked. But uses a stateless iterator which gets the state from the for loop. With the change for each call a new closure is created which contains the gmatch
state. So now direct calls and the for loop works.