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

Const variables in Lua 5.4 #732

Open
asherber opened this issue May 7, 2024 · 2 comments
Open

Const variables in Lua 5.4 #732

asherber opened this issue May 7, 2024 · 2 comments

Comments

@asherber
Copy link
Member

asherber commented May 7, 2024

Lua 5.4 now supports const variables.

local foo <const> = 5
foo = 6  -- runtime error

This sort of thing is very useful for declaring variables that you know shouldn't change. Unfortunately, luacheck doesn't yet include a warning if you do something like the above, so it won't get caught until runtime.

What's the consensus here about using this new construct, assuming that your script requires RGP Lua 0.67 or greater? I'd like to start using it, but I'm a little hesitant without a warning from luacheck if I do something wrong. (Although testing ought to exercise all the pathways and hit the error at runtime.)

@asherber
Copy link
Member Author

asherber commented May 7, 2024

See also lunarmodules/luacheck#109

@rpatters1
Copy link
Collaborator

I've started using <close> in the codebase, and I don't see a problem with <const>. FWIW, besides the lack of luacheck support, another issue is using them with ZeroBrane. The default install of ZeroBrane doesn't (or didn't) include Lua 5.4, so you had to fiddle with the configurations to get it to work with Lua 5.4 syntax. The built-in Lua is useful in ZeroBrane to catch syntax errors before actually running it in Finale. That is to say, its usefulness is limited but existent. I still don't have my ZeroBrane configured for Lua 5.4.

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

No branches or pull requests

2 participants