(topic deleted)

(this post has been deleted by its author)

15 Likes

i do like the idea of constants but i dont really think they’d be useful in a interpreted language like luau as they can’t be evaluated or folded and would serve only as a readability thing

on the other hand languages that transpile to luau should definitely take advantage of being a transpiled language and implement constant folding

They can, in fact, be folded, although you can’t assign any new values to the variable, as the bytecode compiler will turn it back into an upvalue:

--!optimize 2
local const = 12

print(const) -- will be replacaced by a built in 12
1 GETIMPORT R0 1; print
2 LOADN R1 12
3 CALL R0 1 0
4 RETURN R0 0

Variable folding is only available on optimization levels 1 and above. This can be viewed in:

This is also documented in:

2 Likes

i did not know roblox had a optimization mode thanks