Introduction
Luau (pronounced "Lu-ow") started as an internal fork of Lua 5.1 at Roblox to support millions of developers building games on the platform. It adds a gradual type system, better performance, and modern language features while maintaining backward compatibility with standard Lua.
What Luau Does
- Provides a Lua-compatible scripting language with gradual typing
- Performs type inference to catch errors without requiring annotations
- Compiles to a custom bytecode with a fast interpreter and JIT compiler
- Embeds easily into C/C++ host applications via a simple API
- Supports sandboxing for safe execution of untrusted scripts
Architecture Overview
Luau consists of a compiler that produces bytecode, a bytecode interpreter, and a native code generator for x64 and ARM64. The type checker runs as a separate analysis pass and supports both strict and nonstrict modes. The runtime is designed for low-latency environments, with incremental garbage collection tuned for interactive applications.
Self-Hosting & Configuration
- Build from source using CMake on Linux, macOS, or Windows
- Embed by linking the Luau library and initializing a Lua state
- Use
luau_compile()to compile source to bytecode ahead of time - Enable the type checker with
--!strictor--!nonstrictdirectives - Configure sandboxing by restricting available standard library functions
Key Features
- Gradual type system with inference eliminates common runtime errors
- Native code generation (JIT) for x64 and ARM64 platforms
- Backward compatible with Lua 5.1 syntax and semantics
- Incremental garbage collector tuned for real-time applications
- String interpolation, compound assignment, and other syntax improvements over Lua
Comparison with Similar Tools
- Lua 5.4 — Standard Lua lacks a type system and JIT; Luau adds both while staying compatible
- LuaJIT — Faster JIT for Lua 5.1 but no type system; Luau trades peak throughput for type safety
- Teal — Typed Lua that transpiles to Lua; Luau is a native implementation with its own runtime
- MoonScript — CoffeeScript-like syntax for Lua; Luau extends Lua syntax without changing its feel
FAQ
Q: Is Luau only for Roblox development? A: No. Luau is open source and can be embedded in any C/C++ application. It is used outside Roblox in game engines and other projects.
Q: Can I run existing Lua 5.1 scripts in Luau? A: Most Lua 5.1 code runs without changes. Some differences exist in string patterns and coroutine behavior.
Q: Does Luau support LuaRocks packages? A: Not directly. LuaRocks packages targeting the C Lua API need adaptation for the Luau API differences.
Q: How does the gradual type system work? A: Type annotations are optional. Luau infers types where possible and only reports errors where it can prove a type mismatch. Strict mode requires all types to be resolvable.