IMO the ability to unfreeze a table would void the point of it. The point of freezing is to create immutability, and so the solution would be to copy the table and use that as the unfrozen version.
This is amazing!!! Easily one of the best updates.
The new performance updates for tables are great, especially as I have multiple projects with large tables storing information.
This is easily the most exciting era of Roblox, I can’t wait for the spike of ultra-fast and performant games to be made.
There’s no way to unfreeze the table; freezing is permanent.
We don’t have plans to add __close
; if const locals ever get added it’ll be through const var = value
syntax, not the Lua 5.4 <>
syntax that we are unlikely to ever adopt.
Is there any performance benefit to freezing a table? or is it purely to provide immutability?
If there isn’t right now, is it possible that there will be in the future?
Interesting update.
A way more shorter to set a value with if statements.
Really exiting of what is coming next!
Are there any clear benefits of using if
, then
, and else
over and
and or
? This is the only thing I can find:
I tend to use and
and or
on small to medium lengthed statements, and reserve if
, else
, and elseif
for longer statements or blocks of code that require the creation of new variables:
local x: number = 1
print(x == 1 and "x is 1!" or "x is not 1!") -- I'd use this
print(if x == 1 then "x is 1!" else "x is not 1!") -- Rather than this
If I do it with if
, else
, and elseif
it just feels improper as it basically functions like normal if
, else
, and elseif
but on one line.
I guess if you want to return nil or false in some situations, using logical operators will break your code. For example:
local a = (b==c and nil) or (b>c and false) or (b<c and true)
The following practical code does not work as expected with the and/or pattern:
local myObject = nil
local myDefault = Instance.new(...)
local condition = true
print(condition and myObject or myDefault) --> myDefault... ??
It turns out that this situation is extremely easy to run into in practice, and has been the cause of a lot of bugs in our Lua code, especially related to fast flagging since fast flagging often involves branching in table creation expressions etc which was most easily done with and/or.
There’s currently no performance benefit to freezing. We are considering an optimization for metatable lookup where frozen metatables will be faster in OOP scenarios but this hasn’t been designed yet so for now I would not recommend making performance-related assumptions here.
Another similar example for this type of error is when the “true” alternative is a boolean with the value false, e.g.
local fooHidden = foo and foo.hidden or true
always evaluates to true
, although false
may be intended when foo.hidden == false
.
Wouldn’t you use math.min for that?
There is a problem with indentation and end autocompletion when using if expressions:
Luau (+ studio autocomplete!) is my favorite feature of roblox.
Keep it up!
__close would be better as __destroy
for Luau.
As a temporary workaround, you can wrap the expressions in parentheses.
Will the new Luau be forced?
I dont wanna learn an entirely new coding engine after I just finished learning Lua.
Luau is an extended version of lua. In fact, Roblox has used luau for some time already.
If you’ve learnt to code in lua there’s absolutely no difference other than some handy additions we didn’t get in the original lua. And those differences are way too small to call luau an entirely different language, or even engine.
You’re already using Luau if you write any code in roblox. Luau is meant to be easy to adopt if you know Lua and is completely backwards compatible.
You’re already using LuaU right now as you write your roblox code. I think you mean strict type checking instead, which likely won’t ever be forced; as it would break every existing game not using it.