Luau Recap: February 2021

I think the recent optimizations to lua u are much needed, and despite not wanting to script to rely on the new optimizations it allows for creators to push the envelope even more and I appreciate that

5 Likes

Type assertions are very cool, thank you. :slight_smile:

Are there any plans for something like !? Type assertions can replace that but they’re a bit verbose comparatively.

8 Likes

One problem I’ve been encountering is that arrays are only allowed to have one type. e.g.

--!strict
type A = number | string
type T = {A}

local a: T = {1, "A"} --> W000: (5,17) Type 'string' could not be converted into 'number'
local b: T = {"A", 1} --> W000: (6,19) Type 'number' could not be converted into 'string'

print(a, b)

It seems that the type of the first element of an array forces the type of the remaining elements.

For comparison, typescript handles this just fine:

type A = number | string
type T = A[]

let a: T = [1, "A"]
let b: T = ["A", 2]

console.log(a, b)
11 Likes

Using the usual call syntax. We currently don’t have plans to allow an easy syntax to specify the argument types because they should almost always be inferrable from the arguments (if that ever fails us we might consider turbofish)

8 Likes

I think this attachment will help to make better games’s although I’m not scripting I think this will help.

4 Likes

I really love the initiative behind typed luau, and I can’t wait to get more features (I’m already using type assertions in certain scenarios and loving it).

However, there’s one big issue with Team Create and strict/nonstrict mode that forces me to completely disable strict/nonstrict mode:

I have to keep all of my code, typed or untyped, on --!nocheck mode until this is fixed. It sucks, but these unknown require warnings slow down my workflow so much that there’s no way around it. I’m hoping, eventually, I’ll be able to mass find and replace --!nocheck with --!strict, but this issue has affected me since the first release of the type syntax.

@zeuxcg

5 Likes

not gonna lie the type checking screwed with my mind a bit (lol)

but i am most definitely looking forward to the generic function types, future is looking bright!

4 Likes

Now I do question.
Once type checking and such is out as in, officially released, no longer in beta.
If enabled, must every script in game use type checking or can it be enabled for individual scripts?
Those are questions I still have about it.

If type checking improves performance, I use it to speed up the game, mostly in scripts that are tied to renderstep or where fast calculations is a must.
But for some scripts where performance/speed is not that important, type checking gets a little tedious to apply to every variable and function so then I choose to not use it.

4 Likes

we’ll be able to create types like in typescript ?

5 Likes

That’s what the --!strict you see at the top of the examples is, you can specify one of several different options after the ! for whether / how strictly to typecheck that specific script.

8 Likes

This is already possible:

type vector1 = {
    x: number
}

local v1: vector1 = { x = 10 } -- ok
local v1_bad: vector1 = { x = 10, y = 5 } -- will lint that this is bad
7 Likes

There is this very annoying bug where classes have a blue underline when they have been added to a part and the script that references it exists before it is added to whatever parent it is in. Another annoying bug is that studio seems to get laggier the longer you use it but if you restart your pc it’s all fine.

5 Likes

Thank you, that’s something I already was aware of.

But I meant, will this still be the case once type checking and all is fully released out of beta, stable, optimized and ready as a complete feature?

Will we still be able to enable and disable for specific scripts or must it then be enabled globally in order to benefit from optimizations and such?

I specifically use type checking for scripts that need to be fast, precise and memory efficient, not for the convenient syntaxing, type locking or such, I’m fine with regular lua for most things.

I specifically use it for optimizing so the interpreter knows for example how much memory is really needed or must be allocated for an variable and all.
I purely use it for speed and memory efficiency, if it just serves as a convenient syntax it practically has no use for me.

4 Likes

I love generic methods in C#
Can’t wait to see them here as well

Thanks a lot for the updates

9 Likes

Yes, those annotations are part of the Language spec, not just a temporary beta thing: Type checking - Luau

As for how type-system driven optimization will interact with mixed code, that’s a hard problem. At the end of the day you’ll have to profile and see when that eventually becomes available, however, using type assertions and other techniques it’s a safe bet that you will always be able to kick the available optimizations into working for whatever specific pieces of code you need to make fast even if the rest of your code doesn’t have annotations.

6 Likes

There’s also this bug where after having studio open for a while, studio will stop auto completing global variables:


Just noticed in the video it says luau ran into an error and will not type check until studio is restarted.

6 Likes

This is absolutely true and annoying. How do you disable LuaU?

3 Likes

You can’t disable Luau, it’s literally the language you use to code in Roblox. You’re thinking of the Luau Type Checker, in which case, you can’t since it’s built in.

5 Likes

Luau is the variant of Lua that roblox runs on. It is basically what people call “Roblox Lua”. It has the stuff roblox has in it. Pure lua is very similarly. Luau is just a fork of Lua with better features and such to work on Roblox.

3 Likes

Did you read what I even said… Compound operators for the logical AND/OR operators

2 Likes