Luau source code parser, compiler, and type checker.
Parses Luau source into a structured AST (Abstract Syntax Tree) with
full type-safety. Also provides bytecode compilation, loading, native
JIT compilation, bytecode disassembly, full type checking, type
inference at positions, and autocompletion.
Parses Luau source code and returns a structured AST.
The returned root is a Block node whose body contains an array
of statement nodes. Every node carries a type string discriminator
and a location with 1-based line/column positions.
Pass { captureComments = true } to include a comments array in
the result.
local result = luau.parse(source, { captureComments = true })
print("Lines:", result.lines)
print("Errors:", #result.errors)
print("Top-level statements:", #result.root.body)
Parameters
source: string
The Luau source code string to parse.
Parse options (e.g. comment capture).
Returns
The parse result containing the AST root, errors, and optional comments.
Pretty-prints Luau source code by round-tripping through the parser.
luau.prettyPrint(source: string) → string
Parameters
source: string
The Luau source code to format.
Returns
string
The reformatted source code.
Compiles Luau source code to bytecode.
The returned bytecode blob can be passed to load or cached for
later use. If the source has syntax errors the bytecode will contain
an encoded error that load will surface.
local bytecode = luau.compile(source, { optimizationLevel = 2 })
local fn = luau.load(bytecode, "=cached")
fn()
Parameters
source: string
The Luau source code to compile.
Compiler options (optimization, debug, coverage levels).
Returns
string
The compiled bytecode blob.
Loads Luau source code or pre-compiled bytecode as a callable function.
Accepts either a source string (which will be compiled automatically)
or a bytecode blob previously returned by compile. This is the
equivalent of loadstring in standard Lua.
local fn = luau.load("return 1 + 2", "=example")
print(fn())
luau.load(sourceOrBytecode: string, chunkname: string?) → ((...any) → ...any)
Parameters
sourceOrBytecode: string
Luau source code or compiled bytecode.
chunkname: string?
Optional name for the chunk (shown in errors/stack traces, defaults to "=load").
Returns
((...any) → ...any)
The loaded function.
Returns a human-readable bytecode listing for the given source.
Compiles the source and returns a formatted disassembly string showing
every function's bytecode instructions, optionally with source lines,
local variable info, compiler remarks, and type annotations.
local listing = luau.disassemble(source, {
showLocals = true,
showRemarks = true,
})
print(listing)
Parameters
source: string
The Luau source code to disassemble.
Disassembly options controlling output detail.
Returns
string
The formatted bytecode listing.
Runs the Luau type checker on a source string.
Returns a CheckResult containing any type errors found. When
options.annotate is true, also returns the source code rewritten
with inferred type annotations attached to every binding and
expression. The result also includes built-in Luau lints under
result.lints.
local result = luau.check(source, { mode = "strict", annotate = true })
for _, err in result.errors do
print(err.message, err.location.start.line)
end
if result.annotated then
print(result.annotated)
end
Parameters
source: string
The Luau source code to type-check.
Returns
Infers the type at a specific position in Luau source code.
Runs the type checker in strict mode (by default) and queries the
inferred type at the given 1-based line and column. Useful for
building LSP hover information or type inspection tools.
Returns nil if no type can be determined at that position (e.g.
whitespace, comments, or if the position is out of range).
local source = "local x = 42\nprint(x)"
local ty = luau.typeAt(source, 1, 7)
print(ty)
Parameters
source: string
The Luau source code.
line: number
1-based line number.
column: number
1-based column number.
Returns
The inferred type as a string, or nil.
Computes autocompletion entries at a cursor position.
Runs type checking and returns contextual completions, including
property names, local bindings, keywords, and types - along with
their inferred types where available. This is the same engine
used by Luau language servers.
local source = 'local t = {foo = 1, bar = "hi"}\nt.'
local result = luau.autocomplete(source, 2, 3)
for name, entry in result.entries do
print(name, entry.kind, entry.type)
end
Parameters
source: string
The Luau source code.
line: number
1-based line number of the cursor.
column: number
1-based column number of the cursor.
Returns
Resolve a require() path relative to a source file.
Given the absolute path of a Luau source file and a require string
(relative path like "./foo", "../bar", or alias path like
"@alias/mod"), returns the absolute path to the resolved module
file, or nil if no matching file was found.
Uses the same resolution rules as the type checker:
- Extension search order:
.luau -> .lua -> dir/init.luau -> dir/init.lua
- Alias resolution via
.luaurc files walking up the directory tree.
init.luau files resolve relative requires from the parent directory.
local target = luau.resolve("C:/project/src/main.luau", "./utils")
print(target)
luau.resolve(filePath: string, requirePath: string) → string?
Parameters
filePath: string
Absolute path of the source file containing the require.
requirePath: string
The require string to resolve.
Returns
string?
Absolute path to the resolved file, or nil.
A position in source code (1-based line and column).
line: number
column: number
A span in source code, from a start Position to an end Position.
A parse error with its location in the source.
message: string
captureComments: boolean?
name: string?
deprecatedInfo: { deprecated: boolean, use: string?, reason: string? }?
kind: "Type" | "TypePack" | "Unknown"
type: "TypeReference"
hasParameterList: boolean
name: string
prefix: string?
type: "TypeSingletonBool"
value: boolean
type: "TypeSingletonString"
value: string
Union of all type-pack nodes (used for return types and variadic packs).
type: "ExprConstantNumber"
value: number
parseResult: "Ok" | "Imprecise" | "Malformed" | "BinOverflow" | "HexOverflow" | "Unknown"
type: "ExprConstantString"
value: string
quoteStyle: "QuotedSimple" | "QuotedSingle" | "QuotedRaw" | "Unquoted" | "Unknown"
isQuoted: boolean
kind: "List" | "Record" | "General"
type: "ExprTypeAssertion"
type: "StatCompoundAssign"
hasSemicolon: boolean
op: string
type: "StatLocalFunction"
hasSemicolon: boolean
type: "StatDeclareGlobal"
hasSemicolon: boolean
name: string
type: "StatDeclareFunction"
hasSemicolon: boolean
name: string
vararg: boolean
type: "StatDeclareExternType"
hasSemicolon: boolean
name: string
superName: string?
Any AST node (statement, expression, or type annotation).
The result returned by parse.
lines: number
optimizationLevel: number?
debugLevel: number?
coverageLevel: number?
typeInfoLevel: number?
optimizationLevel: number?
debugLevel: number?
showLocals: boolean?
showRemarks: boolean?
showTypes: boolean?
A definition source for loading type definitions.
Can be a plain string (the definition source text) or a table with
a source field and optional name (package name, e.g. "@mygame").
mode: ("strict" | "nonstrict" | "nocheck")?
Type-checking mode: "strict" for full checking, "nonstrict" (default)
for lenient checking, "nocheck" for no type checking.
annotate: boolean?
If true, the result includes an annotated field with the source
rewritten to include inferred type annotations.
Additional type definition sources to load before type checking.
These are .d.luau-style definition strings that declare global
types and functions available in the checked source.
filePath: string?
Absolute file path of the source being checked. When provided,
require() calls in the source are resolved relative to this path,
and .luaurc alias configs are discovered by walking up from it.
A type error from the type checker.
message: string
Human-readable error message.
Source location of the error.
category: "TypeError" | "SyntaxError"
Error category: "TypeError" or "SyntaxError".
A lint diagnostic produced by Luau's built-in linter.
severity: "error" | "warning"
code: number
name: string
Stable lint code name (for example "LocalUnused").
message: string
Human-readable lint message.
Source location for the lint.
Lint diagnostics grouped by severity plus flattened ordering.
The result returned by check.
Type errors found during checking (empty array if none).
Built-in Luau lint diagnostics for this source.
annotated: string?
The source code with inferred type annotations attached.
Only present when options.annotate is true.
display: string
source: "Expression" | "Binding" | "ScopeBinding"
mode: ("strict" | "nonstrict" | "nocheck")?
Type-checking mode. Defaults to "strict" for best inference.
Additional type definition sources to load before inference.
filePath: string?
Absolute file path of the source. Enables require() resolution.
detailed: boolean?
If true, return a structured type object instead of just a string.
Options for autocomplete.
mode: ("strict" | "nonstrict")?
Type-checking mode. Defaults to "strict" for best results.
Additional type definition sources to load before completion.
filePath: string?
Absolute file path of the source. Enables require() resolution.
detailed: boolean?
If true, include typeDetail for each typed autocomplete entry.
kind: "Property" | "Binding" | "Keyword" | "String" | "Type" | "Module" | "GeneratedFunction" | "RequirePath" | "Unknown"
What kind of completion this is.
type: string?
The inferred type of this entry (absent for keywords).
Structured type metadata (when options.detailed is true).
deprecated: boolean?
Whether this entry is deprecated.
typeCorrect: ("Correct" | "CorrectFunctionResult")?
Whether this entry's type matches what's expected at the cursor.
insertText: string?
Suggested text to insert.
parens: ("CursorAfter" | "CursorInside")?
Parentheses recommendation: "CursorAfter" means add () with
cursor after, "CursorInside" means add () with cursor between.
The result returned by autocomplete.
context: "Expression" | "Statement" | "Property" | "Type" | "Keyword" | "String" | "Unknown"
The autocomplete context at the cursor position.
Map of completion name to entry details.