A fast, small, safe, gradually typed embeddable scripting language derived from Lua
Find a file
vegorov-rbx 97965c7c0a
Sync to upstream/release/576 (#928)
* `ClassType` can now have an indexer defined on it. This allows custom
types to be used in `t[x]` expressions.
* Fixed search for closest executable breakpoint line. Previously,
breakpoints might have been skipped in `else` blocks at the end of a
function
* Fixed how unification is performed for two optional types `a? <: b?`,
previously it might have unified either 'a' or 'b' with 'nil'. Note that
this fix is not enabled by default yet (see the list in
`ExperimentalFlags.h`)

In the new type solver, a concept of 'Type Families' has been
introduced.
Type families can be thought of as type aliases with custom type
inference/reduction logic included with them.
For example, we can have an `Add<T, U>` type family that will resolve
the type that is the result of adding two values together.
This will help type inference to figure out what 'T' and 'U' might be
when explicit type annotations are not provided.
In this update we don't define any type families, but they will be added
in the near future.
It is also possible for Luau embedders to define their own type families
in the global/environment scope.

Other changes include:
* Fixed scope used to find out which generic types should be included in
the function generic type list
* Fixed a crash after cyclic bound types were created during unification

And in native code generation (jit):
* Use of arm64 target on M1 now requires macOS 13
* Entry into native code has been optimized. This is especially
important for coroutine call/pcall performance as they involve going
through a C call frame
* LOP_LOADK(X) translation into IR has been improved to enable type
tag/constant propagation
* arm64 can use integer immediate values to synthesize floating-point
values
* x64 assembler removes duplicate 64bit numbers from the data section to
save space
* Linux `perf` can now be used to profile native Luau code (when running
with --codegen-perf CLI argument)
2023-05-12 10:50:47 -07:00
.github Add DCR solver to analysis benchmarks (#862) 2023-03-13 13:58:29 -07:00
Analysis Sync to upstream/release/576 (#928) 2023-05-12 10:50:47 -07:00
Ast Add missing include for integer types (#925) 2023-05-09 11:42:13 -07:00
bench Sync to upstream/release/576 (#928) 2023-05-12 10:50:47 -07:00
CLI Sync to upstream/release/576 (#928) 2023-05-12 10:50:47 -07:00
CodeGen Sync to upstream/release/576 (#928) 2023-05-12 10:50:47 -07:00
Common/include/Luau Sync to upstream/release/576 (#928) 2023-05-12 10:50:47 -07:00
Compiler Sync to upstream/release/575 (#919) 2023-05-05 14:52:49 -07:00
docs Fix grammar issues (#915) 2023-05-04 05:39:18 -07:00
extern Sync to upstream/release/536 (#592) 2022-07-14 15:52:26 -07:00
fuzz Sync to upstream/release/572 (#899) 2023-04-14 11:06:22 -07:00
papers Fix HATRA '21 README.md formatting (#118) 2021-11-04 09:00:41 -05:00
rfcs RFC: Floor division operator (#832) 2023-03-20 15:12:48 -07:00
tests Sync to upstream/release/576 (#928) 2023-05-12 10:50:47 -07:00
tools Sync to upstream/release/576 (#928) 2023-05-12 10:50:47 -07:00
VM Sync to upstream/release/576 (#928) 2023-05-12 10:50:47 -07:00
.clang-format Sync to upstream/release/501 (#20) 2021-11-01 14:52:34 -07:00
.gitignore Sync to upstream/release/539 (#625) 2022-08-04 15:35:33 -07:00
CMakeLists.txt Luau.Analyze.CLI must link pthreads on Linux. (#920) 2023-05-05 15:41:46 -07:00
CONTRIBUTING.md Update CONTRIBUTING.md 2021-12-02 23:08:45 -08:00
LICENSE.txt Update copyright years. (#323) 2022-01-20 09:42:49 -08:00
lua_LICENSE.txt Sync to upstream/release/501 (#20) 2021-11-01 14:52:34 -07:00
Makefile Sync to upstream/release/574 (#910) 2023-04-28 12:55:13 -07:00
README.md docs: update readme installation guide (#792) 2023-02-23 13:08:45 -08:00
SECURITY.md Update SECURITY.md 2023-03-01 14:40:40 -08:00
Sources.cmake Sync to upstream/release/576 (#928) 2023-05-12 10:50:47 -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). 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, as well as 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.

This repository hosts source code for the language implementation and associated tooling, documentation for the language as well as RFCs and other materials. The documentation portion of this repository can be viewed at https://luau-lang.org/

Usage

Luau is an embeddable 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 type checking and linting documentation.

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):

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/macOS you can 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 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), or lack of __gc support (use lua_newuserdatadtor instead).

To gain advantage of many performance improvements it's highly recommended to use safeenv feature, which sandboxes individual scripts' global tables from each other as well as protects builtin libraries from monkey-patching. For this to work you need to call luaL_sandbox for 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 bytecode compiler and type checker/linter tests) and Luau.Conformance (for 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 and can be ran via make test.

Dependencies

Luau uses C++ as its implementation language. The runtime requires C++11, whereas 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 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 Lua 5.x implementation that is MIT licensed as well.

When Luau is integrated into external projects, we ask to honor the license agreement and include Luau attribution into the user-facing product documentation. The attribution using Luau logo is also encouraged.