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

"match is unsupported" error message should be improved #1503

Open
Zamiell opened this issue Oct 17, 2023 · 2 comments
Open

"match is unsupported" error message should be improved #1503

Zamiell opened this issue Oct 17, 2023 · 2 comments
Labels
enhancement scope: transformation Transformation of TS to Lua

Comments

@Zamiell
Copy link
Contributor

Zamiell commented Oct 17, 2023

The message should explicitly tell you to use string.match(foo, regex).

@Z3rio
Copy link
Contributor

Z3rio commented Oct 17, 2023

Could you please supply a sample ts snippet to show what the issue is a bit more specifically, thank you :)
(Or a link to the playground)

@Zamiell
Copy link
Contributor Author

Zamiell commented Oct 17, 2023

Sorry, I was not clear enough in the original post.

Consider the following code snippet, which is extremely common:

const string1 = "The quick brown fox jumps over the lazy dog.";
const match = string1.match("brown (\w+) jumps");

The playground for this is here:
https://typescripttolua.github.io/play#code/MYewdgzgLgBNBOBLMBzAjDAvDARAFQAsBTGARwFdFgBrGAI3hAHcwYAzEADxgCtyBbAA4QYIAG5F4MKMRgAbAIYAvAJ4wAJiBQA6HAG4AUKEix+CqMAJY4UJKjTazFggAocDZqxcAdJgGoASl4BYRwAwyA

We can see that it throws the error:
"string.match is unsupported".

But this error message sucks and is misleading, because what it really means is that the String.match method is unsupported. The Lua string.match is absolutely supported.

What we really need to do here is to reconfigure the code to look like this:

const string1 = "The quick brown fox jumps over the lazy dog.";
const match = string.match(string1, "brown (%w+) jumps");

So, in conclusion, I think the error message should say:

The String.match method is unsupported. Consider including the Lua types for your environment and then changing the code to string.match(foo, regex) instead. Note that the Lua match works differently than the JavaScript/TypeScript match, so for example you would have to change \w+ to %w+.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement scope: transformation Transformation of TS to Lua
Projects
None yet
Development

No branches or pull requests

3 participants