Skip to content

Const variables in Lua 5.4 #732

@asherber

Description

@asherber

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions