A fast, small, safe, gradually typed embeddable scripting language derived from Lua
Find a file
Hunter Goldstein 92cce5776c
Sync to upstream/release/674 (#1832)
# General

* Expose an optional `get_alias` API as an alternative to `get_config`
in Luau.Require and Luau.RequireNavigator.
* Improve the Luau CLI's virtual filesystem implementation to fix bugs
related to `init.luau`. Fixes
https://github.com/luau-lang/luau/issues/1816


# New Type Solver

* Avoid double reporting errors when erroneous arguments are provided to
type functions.
* Fix some instances of unresovable cyclic type functions in loops by
only considering the first loop cycles. This results in some type
inference inaccuracies when the type of a variable in loop through
multiple iterations. Fixes
https://github.com/luau-lang/luau/issues/1413.
* Better generalize free types that have meaningful lower and upper
bounds, especially for table indexers.
* Report more specific errors when assigning or returning table literal
types, instead of citing the *entire* table type.
* Inference for functions with generic type packs is greatly improved.
* Fix some internal compiler exceptions when using type-stating
functions like `table.freeze` in `if _ then _ else _` expressions and
short circuiting binary operations.
* More consistently simplify unions of primitive types, especially in
array-like and dictionary-like tables.
* Fix a crash when type checking an erroneous type alias containing
`typeof` with a type assertion expression, as in:
  ```
  type MyTable = {}
  -- This will error at type checking time as it's a duplicate
  type MyTable = typeof(setmetatable(SomeTable :: {}, SomeMetaTable));
  ```
* Fix a crash when inferring the type of an index expression where the
indexee is invalid (e.g. `nil`).

# Runtime
* Avoid throwing an exception from `luau_load` if we run out of memory.
* Type functions are no longer compiled and included in bytecode. Fixes
#1817.
* Fix some instances of Luau C API functions reading invalid debug
information (generally when the first or last instruction of a block was
being inspected). Fixes #1369.
* Avoid potential signed integer overflow when doing bounds checks on
tables.
* Support 16 byte aligned userdata objects when system allocation
alignment is also 16 bytes.
* Fix memory leaks in `Luau.Require` when using VM build with no
exceptions. Fixes #1827.

---------

Co-authored-by: Andy Friesen <afriesen@roblox.com>
Co-authored-by: Ariel Weiss <aaronweiss@roblox.com>
Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com>
Co-authored-by: James McNellis <jmcnellis@roblox.com>
Co-authored-by: Sora Kanosue <skanosue@roblox.com>
Co-authored-by: Talha Pathan <tpathan@roblox.com>
Co-authored-by: Varun Saini <vsaini@roblox.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
2025-05-16 12:39:58 -07:00
.github chore: update applicable .lua files to .luau (#1560) 2025-02-21 14:29:20 -08:00
Analysis Sync to upstream/release/674 (#1832) 2025-05-16 12:39:58 -07:00
Ast Sync to upstream/release/674 (#1832) 2025-05-16 12:39:58 -07:00
bench Add 2-component vector constructor (#1569) 2025-01-17 08:45:03 -08:00
CLI Sync to upstream/release/674 (#1832) 2025-05-16 12:39:58 -07:00
CodeGen Sync to upstream/release/674 (#1832) 2025-05-16 12:39:58 -07:00
Common/include/Luau Sync to upstream/release/664 (#1715) 2025-03-07 10:07:27 -08:00
Compiler Sync to upstream/release/674 (#1832) 2025-05-16 12:39:58 -07:00
Config Sync to upstream/release/674 (#1832) 2025-05-16 12:39:58 -07:00
EqSat Sync to upstream/release/662 (#1681) 2025-02-21 10:24:12 -08:00
extern Sync to upstream/release/597 (#1054) 2023-09-29 18:13:05 -07:00
fuzz Sync to upstream/release/674 (#1832) 2025-05-16 12:39:58 -07:00
Require Sync to upstream/release/674 (#1832) 2025-05-16 12:39:58 -07:00
tests Sync to upstream/release/674 (#1832) 2025-05-16 12:39:58 -07:00
tools Bump jinja2 from 3.1.4 to 3.1.5 in /tools/fuzz (#1607) 2025-02-17 08:58:48 -08:00
VM Sync to upstream/release/674 (#1832) 2025-05-16 12:39:58 -07:00
.clang-format Sync to upstream/release/637 (#1354) 2024-08-02 07:30:04 -07:00
.gitignore Sync to upstream/release/652 (#1525) 2024-11-15 14:29:30 -08:00
CMakeLists.txt Sync to upstream/release/669 (#1770) 2025-04-11 17:44:21 -07:00
CMakePresets.json Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
CONTRIBUTING.md Revise some of the copytext in markdown files. (#1677) 2025-02-20 13:56:00 -08:00
LICENSE.txt Sync to upstream/release/669 (#1770) 2025-04-11 17:44:21 -07:00
lua_LICENSE.txt Sync to upstream/release/501 (#20) 2021-11-01 14:52:34 -07:00
Makefile Sync to upstream/release/674 (#1832) 2025-05-16 12:39:58 -07:00
README.md Update Arch Linux installation instructions (#1774) 2025-04-14 08:47:49 -07:00
SECURITY.md Revise some of the copytext in markdown files. (#1677) 2025-02-20 13:56:00 -08:00
Sources.cmake Sync to upstream/release/674 (#1832) 2025-05-16 12:39:58 -07:00

Luau CI codecov

Luau (lowercase u, /ˈlu.aʊ/) is a fast, small, safe, gradually typed embeddable scripting language derived from Lua.

It is designed to be backwards compatible with Lua 5.1, as well as incorporating some features from future Lua releases, but also expands the feature set (most notably with type annotations and a state-of-the-art type inference system). Luau is largely implemented from scratch, with the language runtime being a very heavily modified version of Lua 5.1 runtime, with completely rewritten interpreter and other performance innovations. The runtime mostly preserves Lua 5.1 API, so existing bindings should be more or less compatible with a few caveats.

Luau is used by Roblox game developers to write game code, and by Roblox engineers to implement large parts of the user-facing application code as well as portions of the editor (Roblox Studio) as plugins. Roblox chose to open-source Luau to foster collaboration within the Roblox community as well as to allow other companies and communities to benefit from the ongoing language and runtime innovation. More recently, Luau has seen adoption in games like Alan Wake 2, Farming Simulator 2025, Second Life, and Warframe.

This repository hosts source code for the language implementation and associated tooling. Documentation for the language is available at https://luau.org/ and accepts contributions via site repository; the language is evolved through RFCs that are located in rfcs repository.

Usage

Luau is an embeddable programming language, but it also comes with two command-line tools by default, luau and luau-analyze.

luau is a command-line REPL and can also run input files. Note that REPL runs in a sandboxed environment and as such doesn't have access to the underlying file system except for ability to require modules.

luau-analyze is a command-line type checker and linter; given a set of input files, it produces errors/warnings according to the file configuration, which can be customized by using --! comments in the files or .luaurc files. For details, please refer to our type checking and linting documentation. Our community maintains a language server frontend for luau-analyze called luau-lsp for use with text editors.

Installation

You can install and run Luau by downloading the compiled binaries from a recent release; note that luau and luau-analyze binaries from the archives will need to be added to PATH or copied to a directory like /usr/local/bin on Linux/macOS.

Alternatively, you can use one of the packaged distributions (note that these are not maintained by Luau development team):

  • macOS: Install Homebrew and run brew install luau
  • Arch Linux: Luau has been added to the official Arch Linux packages repository under the extras repository (see luau), simply install using pacman: pacman -Syu luau
  • Alpine Linux: Enable community repositories and run apk add luau
  • Gentoo Linux: Luau is officially packaged by Gentoo and can be installed using emerge dev-lang/luau. You may have to unmask the package first before installing it (which can be done by including the --autounmask=y option in the emerge command).

After installing, you will want to validate the installation was successful by running the test case here.

Building

On all platforms, you can use CMake to run the following commands to build Luau binaries from source:

mkdir cmake && cd cmake
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build . --target Luau.Repl.CLI --config RelWithDebInfo
cmake --build . --target Luau.Analyze.CLI --config RelWithDebInfo

Alternatively, on Linux and macOS, you can also use make:

make config=release luau luau-analyze

To integrate Luau into your CMake application projects as a library, at the minimum, you'll need to depend on Luau.Compiler and Luau.VM projects. From there you need to create a new Luau state (using Lua 5.x API such as lua_newstate), compile source to bytecode and load it into the VM like this:

// needs lua.h and luacode.h
size_t bytecodeSize = 0;
char* bytecode = luau_compile(source, strlen(source), NULL, &bytecodeSize);
int result = luau_load(L, chunkname, bytecode, bytecodeSize, 0);
free(bytecode);

if (result == 0)
    return 1; /* return chunk main function */

For more details about the use of the host API, you currently need to consult Lua 5.x API. Luau closely tracks that API but has a few deviations, such as the need to compile source separately (which is important to be able to deploy VM without a compiler), and the lack of __gc support (use lua_newuserdatadtor instead).

To gain advantage of many performance improvements, it's highly recommended to use the safeenv feature, which sandboxes individual scripts' global tables from each other, and protects builtin libraries from monkey-patching. For this to work, you must call luaL_sandbox on the global state and luaL_sandboxthread for each new script's execution thread.

Testing

Luau has an internal test suite; in CMake builds, it is split into two targets, Luau.UnitTest (for the bytecode compiler and type checker/linter tests) and Luau.Conformance (for the VM tests). The unit tests are written in C++, whereas the conformance tests are largely written in Luau (see tests/conformance).

Makefile builds combine both into a single target that can be run via make test.

Dependencies

Luau uses C++ as its implementation language. The runtime requires C++11, while the compiler and analysis components require C++17. It should build without issues using Microsoft Visual Studio 2017 or later, or gcc-7 or clang-7 or later.

Other than the STL/CRT, Luau library components don't have external dependencies. The test suite depends on the doctest testing framework, and the REPL command-line depends on isocline.

License

Luau implementation is distributed under the terms of MIT License. It is based on the Lua 5.x implementation, also under the MIT License.

When Luau is integrated into external projects, we ask that you honor the license agreement and include Luau attribution into the user-facing product documentation. Attribution making use of the Luau logo is also encouraged when reasonable.