Luau (programming language)
| File:Luau Logo (Programming Language).svg | |
| File:Excerpt of Coordinates module in Lua.png | |
| Paradigm | Multi-paradigm: scripting, imperative (procedural, prototype-based, object-oriented), functional, meta, reflective |
|---|---|
| Designed by | Roblox Corporation |
| First appeared | 2019 |
| Typing discipline | Dynamic, weak, duck |
| OS | Cross-platform |
| License | MIT License |
| Filename extensions | .luau |
| Website | https://luau.org/ |
| Major implementations | |
| Roblox Studio | |
| Influenced by | |
| Lua | |
Search Luau (programming language) on Amazon.
Luau (lowercase u, /ˈlu.aʊ/) is a fast, small, safe, gradually typed embeddable scripting language derived from Lua. Luau is backwards-compatible with Lua 5.1 and is designed mainly for the popular gaming platform Roblox.[1]
It was developed by Roblox's internal team along with open source contributors. It underpins all user-generated content on Roblox, offering APIs for 3D world manipulation, backend access, UI interaction, and more. Used by hundreds of thousands of developers, Luau is the first programming language for many and essential in Roblox Studio for creating plugins and games.
History
In 2006, Roblox chose Lua as its programming language for users due to its simplicity, efficiency, and suitability for embedding in games, allowing users to script immersive games with ease. However, limitations in type checking, performance, and missing features in Lua 5.1 led to the development of Luau in 2019. Luau maintains backward compatibility with Lua 5.1 but introduces enhancements like gradual typing for large codebases, better performance, and additional features while keeping the language simple and beginner-friendly.
Luau's evolution is guided by a collaborative process involving compiler, runtime, type checker, and tooling development. This ensures efficient execution and practicality, with an emphasis on performance and memory optimization. Future developments will focus on enhancing type inference, exploring native code generation, and innovating in hardware utilization across cores and nodes. Luau continues to be refined to balance simplicity with advanced functionality, supporting the vast and diverse Roblox developer community.
Syntax
The syntax of Luau is similar to Lua 5.1 but also includes the following features:
String literals
\xABinserts a character with the code 0xAB into the string\u{ABC}inserts a UTF8 byte sequence that encodes U+0ABC character into the string (note that braces are mandatory)\zat the end of the line inside a string literal ignores all following whitespace including newlines, which can be helpful for breaking long literals into multiple lines.
Number literals
- Hexadecimal integer literals,
0xABCor0XABC - Binary integer literals,
0b01010101or0B01010101 - Decimal separators in all integer literals, using
_for readability:1_048_576,0xFFFF_FFFF,0b_0101_0101
Continue statement
if x < 0 then
continue -- Not a keyword for backwards compatibility
end
Compound assignments
Luau supports compound assignments with the following operators: +=, -=, *=, /=, //=, %=, ^=, ..=. Just like regular assignments, compound assignments are statements, not expressions:
-- this works
a += 1
-- this doesn't work
print(a += 1)
-- calls foo() twice
a[foo()] = a[foo()] + 1
-- calls foo() once
a[foo()] += 1
Type annotations
-- Type annotations can be declared for local variables, function arguments and function return types using : as a separator
function foo(x: number, y: string): boolean
local k: string = y:rep(x)
return k == "a"
end
-- Function types are specified using the arguments and return types, separated with ->:
local foo: (number, string) -> boolean
-- To return no values or more than one, you need to wrap the return type position with parentheses, and then list your types there.
local no_returns: (number, string) -> ()
local returns_boolean_and_string: (number, string) -> (boolean, string)
function foo(x: number, y: number): (number, string)
return x + y, tostring(x) .. tostring(y)
end
-- Table types are specified using the table literal syntax, using : to separate keys from values
local array: { [number] : string }
local object: { x: number, y: string }
-- Declaring type aliases
type Point = { x: number, y: number }
type Array<T> = { [number]: T }
type Something = typeof(string.gmatch("", "%d"))
If-then-else Statements
-- Simple Example
local maxValue = if a > b then a else b
-- Using elseif
local sign = if x < 0 then -1 elseif x > 0 then 1 else 0
Generalised Iteration
-- No need for next keyword, or pairs() or ipairs()
for k, v in {1, 4, 9} do
assert(k * k == v)
end
String interpolation
-- Use backticks to format strings
local count = 3
print(`Bob has {count} apple(s)!`)
-- Bob has 3 apple(s)!
print`hello` -- Invalid
print "Hello" -- Valid
print(`hello`) -- Valid
References
- ↑ https://luau.org/ Luau's website.
This article "Luau (programming language)" is from Wikipedia. The list of its authors can be seen in its historical and/or the page Edithistory:Luau (programming language). Articles copied from Draft Namespace on Wikipedia could be seen on the Draft Namespace of Wikipedia and not main one.
