gopher-lua icon indicating copy to clipboard operation
gopher-lua copied to clipboard

Return a closure without arguments in gfind

Open waschik opened this issue 1 year ago • 1 comments

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.

waschik avatar Dec 14 '23 11:12 waschik

Coverage Status

coverage: 89.623%. remained the same when pulling 467210daee147508f1abfed52dcb82c28dd27f3f on waschik:gfind-noarg-closure into 2348fd042596f47bf9a1018a01f365ca3bf19134 on yuin:master.

coveralls avatar Dec 14 '23 11:12 coveralls