Skip to content

Fix string.find and string.match from unexpected explosions #86

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jordan4ibanez
Copy link

I was reading the documentation for string.find and I noticed that in it's own documentation it reads:

/**
  * Looks for the first match of pattern (see §6.4.1) in the string s. If it
  * finds a match, then find returns the indices of s where this occurrence
  * starts and ends; otherwise, it returns nil.
  * /

I see the definition defined as:

function find(
    s: string,
    pattern: string,
    init?: number,
    plain?: boolean
): LuaMultiReturn<[number, number, ...string[]] | []> ;

Perhaps the easiest solution for this would be to simply add optional return parameters as follows:

function find(
    s: string,
    pattern: string,
    init?: number,
    plain?: boolean
): LuaMultiReturn<[number?, number?, ...string[]] | []> ;

So this way, at least you know it might explode instead of blindly walking into an explosion.

Also:
I noticed that string.match could also blow up so I threw that in there.

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.

1 participant