luau/docs/_posts/2021-03-29-luau-recap-march-2021.md
2021-03-29 17:24:26 -05:00

2.1 KiB

layout title
single Luau Recap: March 2021

Luau is our new language that you can read more about at https://roblox.github.io/luau. It's been a busy month in Luau!

[Cross-posted to the Roblox Developer Forum.]

Typed variadics

Luau supports variadic functions, meaning ones which can take a variable number of arguments (varargs!) but previously there was no way to specify their type. Now you can!

function f(x: string, ...: number)
  print(x)
  print(...)
end
f("hi")
f("lo", 5, 27)

This function takes a string, plus as many numbers as you like, but if you try calling it with anything else, you'll get a type error, for example f("oh", true) gives an error " Type boolean could not be converted into number"

Variadics can be used in function declarations, and function types, for example

type T = {
  sum: (...number) -> number
}
function f(x: T)
  print(x.sum(1, 2, 3))
end

Generic functions

[TODO]

Typechecking improvements

  • Check bodies of methods whose self has type any
  • More precise types for debug.* methods
  • Better typechecking for Instance:IsA.

Performance improvements

  • Significantly optimized non-variadic function calls, improving performance by up to 10% on call-heavy benchmarks
  • Improve performance of math.clamp, math.sign and math.round by 2.3x, 2x and 1.6x respectively
  • Optimized coroutine.resume with ~10% gains on coroutine-heavy benchmarks

Library changes

  • Added the debug.info function which allows retrieving information about stack frames or functions; similarly to debug.getinfo from Lua, this accepts an options string that must consist of characters slnfa; unlike Lua that returns a table, the function returns all requested values one after another to improve performance.

Luau now has a shiny new logo!

!["New logo!"]({{ site.url }}{{ site.baseurl }}/assets/images/luau.png)

Coming soon...

  • Generic variadics!
  • Better treatment of cyclic requires!
  • [Anything else?]