Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return a closure without arguments in gfind #466

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

waschik
Copy link
Contributor

@waschik waschik commented Dec 14, 2023

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.

@coveralls
Copy link

Coverage Status

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect behavior for string.gmatch
2 participants