This is huge for roblox, now only for a wikipedia article to be made or even blog posts discussing the language. (w3schools too?)
The moment Luau allows me to add type constraints to generic functions, that is the day I will never ever disable strict again.
Iâd love to do something like a basic interface, and then do composition just based on the type signature alone, not depending on any metamethods.
Something like this (C#)
public interface ITestTestable {
public string GetTestableName();
}
public class Test {
public static void RunTest<T>(T value) where T : ITestTestable {
var name = value.GetTestableName(); // Legal code.
System.Console.WriteLine($"Testable name: {name}");
}
}
would be perfect in Luau to allow us to define a sort of OOP without the inherent costs of metatables.
-- Purely theoretical.
type IGun = { GetBulletCount: (self: IGun) -> number, ToggleDebugFeatures: (self: IGun, enable: boolean) -> () }
type IEnemy = { GetHealth: (self: IEnemy) -> number }
local function TestGun<T: & IGun, U: & IEnemy>(gun: T, target: U)
if gun.GetBulletCount() > 20 then
warn("Weapon has 20 bullets")
end
end
type Pistol = { PerformValidation: (self: Pistol) -> () } & IGun
type Zombie = { PlayGroan: (self: Zombie) -> () } & IEnemy
local pistol = nil :: Pistol
local zombie = nil :: Zombie
TestGun(pistol, zombie)
If this ever comes to be, Iâd actively consider making types for all my Luau projects, no questions asked, because then I can be guaranteed generics wonât be pretty much taking any
with extra steps, which is practically what it is, except on some cases, where you specify the generic type on types that use types that use generics.
Ehhh, that probably wonât happen for a while until Luau spreads a bit further beyond Roblox, as Wikipedia has requirements of notability for an article.
My understanding based on discussions on Discord with the team is that thereâs a resistance to bringing it to the client since there are platforms that donât allow it. While they could enable it for e.g. PC clients, it would make the already significant performance difference even more severe.
Mind you, this is just the vibe I get and not an actual answer. I imagine the official corporate answer is âWe are looking into opportunities to being native codegen to the Roblox clientâ with no followup.
im pretty sure on ios only web browsers are allowed to do that stuff
Not sure if this is your guys team but types are still not highlighted differently from variable names and so at a glance its hard to tell what is a variable and what is a type. Would be great if the types were a different color
Right now itâs difficult/impossible to tell if weâre hitting the fast path when a fast path is available.
Is it possible to get a flag similar to !native that will give us feedback on if weâre hitting the slow path?
Yes, we seal the tables returned from a function. This will be true in the new type checker as well.
This is something that will be fixed in the new type checker.
But be aware that there might be temporary bugs in the Beta that we plan to release.
This will not be included in the new type checker.
We are aware of some developers requesting this, but there is no plan to extend the type system this way.
There are no plans to have this in the type system.
There were a few feature requests for this before, we do not plan to implement this.
One of the recent ones was Allow optional enforcing of static typing in functions, methods, and variables
We are exploring options to bring native code generation on desktop clients.
We are aware that desktops are already more powerful and such a system has a bigger need on mobile platforms, but those often place artificial limitations on porting the system there.
While there is a risk to make the performance gap between mobile and desktop larger, we donât want to artificially limit performance where it can be unlocked.
Iâve notified the team, but feel free to submit an official Bug Report for better tracking of the fix progress.
Luau subtyping rules allow just specifying the base type instead of having to constrain generics like in C#.
You can just say that function accepts interfaces which satisfy IGun/IEnemy and pass Pistol or Zombie.
We have an extension to the type system coming that will allow specifying read-only and write-only fields which will help describing these interfaces without getting false positive type conversion errors rfcs/docs/syntax-property-access-modifiers.md at 66e1e2a434f8969a6ddd4ace8f581ecade1ac4f6 ¡ luau-lang/rfcs ¡ GitHub
You can track the feature request for this here: Separate syntax highlighting color for type annotations
While itâs very sad how old the request is, we hope to implement it this year.
This is especially true for Vector3
type annotations where itâs impossible to tell if the compiler figured the type out or not.
We plan to have tooling in Studio to display that information after a playtest in the future.
The @checked
annotations are a feature weâre using to support the new non-strict mode in the new type solver that weâve been working on. More information will come out about its meaning in future announcements, so stay tuned!
thx for wonderful updates :DD
Although it worked fine in VS Code,
requiring a large module from another script in Studio often returned an *error-type*
and couldnât recognize some exported types, showing them only as âanyâ.
There werenât any wrong types, but it returned *error-type*
This bug had been very annoying for several months
However, it was fixed after this Luau recap update
I donât know why the bug occurred or how it was fixed, but I hope the bug doesnât reappear
It was truly painfulâŚ
I was quite unsure of the cause, so I hesitated to write a bug report, but it has been fixed now.
Another
Additionally, there is another issue that only occurs in Roblox Studio, not in VS Code using the Luau LSP.
It seems that this issue is specific to Roblox Studio rather than Luau, so Iâm writing it here instead of on the Luau GitHub bug reports.
from Release Note 601
When using union & or intersection | more than about 200 times in Lua, an orange line appears on the top line, and I can no longer export types or use auto-completion. All types become any.
This does not happen when using Luau LSP in VS Code.
I donât know if thereâs a type limit specific to Roblox Studio, but if there is, I hope it gets removed.
I need many union types because I want to implement a constructor function type like Instance.new("Class")->Class
.
e.g.
type Constructor<name = string, class = any> = (name: name)->(class)
type newFn =
& Constructor<"Part", Part>
& Constructor<"MeshPart", MeshPart>
& Constructor<"Decal", Decal>
& Constructor<"AnotherPart", {Another: boolean} & Part>
& Constructor<"CustomInstance", {Name: string, Age: number}>
& Constructor<"Humanoid", Humanoid>
local new: newFn
local meshPart = new("MeshPart")
local anotherPart = new("AnotherPart")
if anotherPart.Another then
-- ...
end
Imo Roblox Studio types should have as few limitations as possible, as long as they donât cause syntax or structural issues (even if it affects performance due to the lack of count limits)
I donât know if parameter function attributes would be able to replace function types with large union types.
but even if they could, It would be better if the limit on the number of types were removed to allow for the implementation of complex module types (if there is)
The github .luau syntax highlighting shows a distinct color for types
Why does roblox studio itself still not support distinct syntax highlighting for types? My eyes still have to struggle to pick out the parameters from the types in long functions
function a(num :number, cf :CFrame, ReallyLongParameterName :MyOwnCustomType)
ThisIsAnUpvalue:FactoryConstructorServiceHandlerMethod(param :ParamType)
end
wait this is actually very nice?? no more warn(
{x} is deprecated please use {y})
??.
Super cool update, and also pretty excited for the upcoming typesolver!
did you get âdetected possibly infinite typepack growthâ or something in script analysis? i got that for the first time when i was just screwing around with luau limits, i canât remember how i triggered it but it was something like copying and pasting {} & {} & {} & {}
over and over again
i hadnât seen it mentioned anywhere but it only goes away if you fix the issue and restart studio, judging by the message it seems to be a failsafe for if luau analysis completely breaks
I beg for an import
type global, I often run into module require recursion errors when im just requiring an exported type,
can only dream of one day that Luauâs type system can reach the levels of Rustâs algebraic type system or TypeScriptâs type system where I could achieve shenanigans like this
type LastChar<T extends string> = `${T}` extends `${infer Front}${infer Back}` ? Back extends '' ? Front : LastChar<Back> : never
type OddNumbers = '1' | '3' | '5' | '7' | '9'
type IsOdd<T extends number> = LastChar<`${T}`> extends OddNumbers ? true : false
type IsOddOrEven<T extends number> = IsOdd<T> extends true ? "Odd" : "Even"
let N1: IsOddOrEven<5> = "Odd"
let N2: IsOddOrEven<2> = "Even"
let N3: IsOddOrEven<187521923> = "Odd"
why would you want that? it looks ugly as hell
Most good type systems do