Luau Language Documentation
repository·master·Indexed 26 days ago
https://github.com/luau-lang/luauLuau is a fast, small, safe, and gradually typed embeddable scripting language derived from Lua 5.1, designed for high performance and game development. It features a state-of-the-art type inference system, a Control Flow Graph (CFG) in Static Single Assignment (SSA) form for reliable type stating, and CLI tools including a REPL (`luau`), a type checker and linter (`luau-analyze`), and a bytecode analysis tool.
What's inside Luau
- Luau uses a Control Flow Graph (CFG) in Static Single Assignment (SSA) form to facilitate reliable type stating and refinements. This structure allows the analyzer to determine exactly which version of a variable is being referenced at any given point in the code, making it easier to reason about back edges in control flow and enabling advanced analysis like effect tracking.
Use Luau CLI tools
masterLuau provides two primary command-line tools:
luau: A command-line REPL and script runner. Note that the REPL runs in a sandboxed environment and cannot access the file system directly, except forrequire-ing modules.luau-analyze: A command-line type checker and linter. It uses file configuration via--!comments or.luaurcfiles to produce errors and warnings.
Handle Isocline asynchronously
masterIsocline is not thread-safe. All
ic_readline_xxxandic_print_xxxfunctions must be called from a single dedicated thread.To use Isocline in an asynchronous application, run the Isocline functions in a blocking dedicated thread and communicate results back to your async event loop. To unblock a current
ic_readlinecall from another thread (simulating actrl-cwhich returnsNULL), use the thread-safeic_async_stop()function.bool ic_async_stop(void)Build Luau from source using Make
masterOn Linux and macOS, you can build the binaries using
make:make config=release luau luau-analyzemake config=release luau luau-analyzeBuild Luau from source using CMake
masterTo build Luau binaries from source on any platform, use CMake with the following commands:
mkdir cmake && cd cmake cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo cmake --build . --target Luau.Repl.CLI --config RelWithDebInfo cmake --build . --target Luau.Analyze.CLI --config RelWithDebInfomkdir cmake && cd cmake cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo cmake --build . --target Luau.Repl.CLI --config RelWithDebInfo cmake --build . --target Luau.Analyze.CLI --config RelWithDebInfoInstall Luau
masterYou can install Luau by downloading compiled binaries from the official releases. Ensure the
luauandluau-analyzebinaries are added to yourPATHor copied to a system directory like/usr/local/binon Linux/macOS.Alternatively, use these community-maintained package managers:
- macOS:
brew install luau - Arch Linux:
pacman -Syu luau - Alpine Linux:
apk add luau - Gentoo Linux:
emerge dev-lang/luau(may require--autounmask=y)
brew install luau- macOS:
Install Isocline as a single source file
masterFor a minimal setup without dependencies, you can add Isocline as a git submodule and compile the source directly into your project.
- Add the submodule:
git submodule add https://github.com/daanx/isocline - Add
isocline/src/isocline.cto your build rules.
$ git submodule add https://github.com/daanx/isocline- Add the submodule:
Build Isocline using CMake
masterTo build Isocline as a static library (
libisocline.aorisocline.lib), clone the repository and use CMake to generate the build files.$ git clone https://github.com/daanx/isocline $ cd isocline $ mkdir -p build/release $ cd build/release $ cmake ../.. $ cmake --build .Choose a CodeGenContext implementation
masterLuau provides two primary implementations of
BaseCodeGenContextfor managing native code generation state. Choose based on your VM architecture:StandaloneCodeGenContext: A VM-specific context. Use this for the "simple" implementation when native code generation is used with a single Luau VM.SharedCodeGenContext: Supports use from multiple Luau VMs concurrently. It allows for sharing of executable native code and related metadata across VMs.
Configure Isocline color palettes via COLORTERM
masterIsocline supports 24-bit colors. If automatic detection fails, you can force a specific color palette by setting the
COLORTERMenvironment variable. Use these values to control color depth:COLORTERM=truecolor: Enables 24-bit colors.COLORTERM=256color: Uses the ANSI 256 color palette.COLORTERM=16color: Uses the regular ANSI 16 color palette (8 normal, 8 bright).COLORTERM=8color: Uses bold for bright colors.COLORTERM=monochrome: Disables all color.
# Example of testing color support gcc -o test_colors -Iinclude test/test_colors.c src/isocline.c ./test_colors COLORTERM=truecolor ./test_colors COLORTERM=16color ./test_colorsRun Luau scripts and files
masterYou can execute Luau scripts by passing file names as arguments. The executable will attempt to find files with.luauor.luaextensions. If you use the-ior--interactiveflag, the REPL will start after the last specified script has finished executing.Enable Native Code Generation (Codegen)
masterLuau supports executing code using native code generation. This can be enabled via several flags:
--codegen: Standard native code generation.--codegen-cold: Includes functions that might not be profitable to natively compile.--codegen-perf: (Linux only) Enables native code generation and profiles usingperf.