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

Prevent compilation when local variable limit is hit #1317

Open
Zamiell opened this issue Jul 27, 2022 · 2 comments
Open

Prevent compilation when local variable limit is hit #1317

Zamiell opened this issue Jul 27, 2022 · 2 comments
Labels
enhancement scope: transformation Transformation of TS to Lua

Comments

@Zamiell
Copy link
Contributor

Zamiell commented Jul 27, 2022

Today, in Discord, we discussed the possibility of TSTL taking extra steps to handle the case of a TSTL program with over 200 local variables.

Right now, it sounds like Perry just wants to keep things as is, given that there are tradeoffs with either option.

However, everyone can agree that run-time errors are terrible - the whole point of using TSTL in the first place is to stop run-time errors. With that in mind, can we make TSTL keep a counter of the current scope's local variables, and then refuse to compile (or throw a warning) if the counter reaches 200? (Or maybe even 190, to be a little on the safe side.)

This would give the end-user the chance to refactor their program long before running into any issues in production!

@Perryvw
Copy link
Member

Perryvw commented Jul 27, 2022

What should the threshold be? Is it the same for every lua target/version?
I guess we would also have to be able to disable it in case there is some weird patched target.

@Perryvw Perryvw added enhancement scope: transformation Transformation of TS to Lua labels Jul 27, 2022
@Zamiell
Copy link
Contributor Author

Zamiell commented Jul 27, 2022

Well, isn't it almost always 200?

See: https://github.com/lua/lua/blob/master/lparser.c#L35
And: https://stackoverflow.com/questions/66511018/lua-how-many-variables-a-local-can-hold

So use 200 * 0.95 as a default, and maybe add it as a compiler option to adjust at will, with a special value of 0 effectively disabling the feature.

@Zamiell Zamiell changed the title Prevent compilation when variable limit is hit Prevent compilation when local variable limit is hit Feb 28, 2023
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

2 participants