Skip to content

luau

luau
local luau = require("@lute/luau")

WARNING

These APIs are still open to future evolution. In new major versions, they may change in backwards incompatible ways.

Summary

EntryDescription
BytecodeCompiled Luau bytecode produced by luau.compile.
CstAttributeA function attribute node (@checked, @native, or @deprecated).
CstElseIfExprAn elseif clause in an if-else expression.
CstElseIfStatAn elseif clause in an if statement.
CstEofThe end-of-file token.
CstExprUnion of all expression node types in the Luau CST.
CstExprBinaryA binary expression node (e.g., a + b).
CstExprCallA function call expression node.
CstExprConstantBoolA boolean literal node (true or false).
CstExprConstantIntegerAn integer literal node.
CstExprConstantNilA nil literal node.
CstExprConstantNumberA number literal node.
CstExprConstantStringA string literal node.
CstExprFunctionAn anonymous function expression node.
CstExprGlobalA reference to a global variable.
CstExprGroupA parenthesized expression node.
CstExprIfElseAn if-else expression node.
CstExprIndexExprA bracketed index expression node (e.g., t[k]).
CstExprIndexNameA dot or colon index expression node (e.g., t.k or t:method).
CstExprInstantiateAn explicit generic instantiation expression node (e.g., f<<T>>).
CstExprInterpStringAn interpolated string expression node (e.g., `hello {name}`).
CstExprLocalA reference to a local variable.
CstExprTableA table constructor expression node.
CstExprTypeAssertionA type assertion expression node (e.g., x :: T).
CstExprUnaryA unary expression node (e.g., not x, -x, #x).
CstExprVarargsA varargs expression node (...).
CstFunctionTypeParameterA parameter in a function type annotation.
CstGenericTypeA generic type parameter (e.g., T in function f<T>).
CstGenericTypePackA generic type pack parameter (e.g., T... in function f<T...>).
CstLocalA local variable binding site in the CST.
CstNodeUnion of all node types in the Luau CST.
CstStatUnion of all statement node types in the Luau CST.
CstStatAssignAn assignment statement node.
CstStatBlockA block statement node (a sequence of statements).
CstStatBreakA break statement node.
CstStatCompoundAssignA compound assignment statement node (e.g., x += 1).
CstStatConstA const variable declaration statement node.
CstStatContinueA continue statement node.
CstStatDoA do...end block statement node.
CstStatExprA statement consisting of a bare expression (e.g., a function call used as a statement).
CstStatForA numeric for loop statement node.
CstStatForInA generic for...in loop statement node.
CstStatFunctionA function declaration statement node.
CstStatIfAn if...then...elseif...else...end statement node.
CstStatLocalA local variable declaration statement node.
CstStatLocalFunctionA local function declaration statement node.
CstStatRepeatA repeat...until loop statement node.
CstStatReturnA return statement node.
CstStatTypeAliasA type alias declaration statement node.
CstStatTypeFunctionA type function declaration statement node.
CstStatWhileA while...do...end loop statement node.
CstTableExprGeneralItemA table constructor entry with a computed key (e.g., [expr] = value).
CstTableExprItemUnion of all table constructor entry types.
CstTableExprListItemA positional table constructor entry (e.g., value in { value }).
CstTableExprRecordItemA named table constructor entry (e.g., key = value).
CstTableTypeItemUnion of all table type entry kinds.
CstTableTypeItemIndexerA computed-key indexer entry in a table type (e.g., [K]: V).
CstTableTypeItemPropertyA named property entry in a table type (e.g., key: T).
CstTableTypeItemStringPropertyA string-literal-keyed property entry in a table type (e.g., ["key"]: T).
CstTypeUnion of all type annotation node types in the Luau CST.
CstTypeArrayAn array type annotation node (e.g., { T }).
CstTypeFunctionA function type annotation node.
CstTypeGroupA parenthesized type annotation node.
CstTypeIntersectionAn intersection type annotation node (e.g., A & B).
CstTypeOptionalAn optional type annotation node (e.g., T?).
CstTypePackUnion of all type pack annotation node types in the Luau CST.
CstTypePackExplicitAn explicit type pack annotation node (e.g., (T, U)).
CstTypePackGenericA generic type pack annotation node (e.g., T...).
CstTypePackVariadicA variadic type pack annotation node (e.g., ...T).
CstTypeReferenceA named type reference node (e.g., string, MyType<T>).
CstTypeSingletonBoolA boolean singleton type node (true or false).
CstTypeSingletonStringA string singleton type node (e.g., "hello").
CstTypeTableA table type annotation node.
CstTypeTypeofA typeof(expr) type annotation node.
CstTypeUnionA union type annotation node (e.g., `A
MultiLineCommentA multi-line block comment trivia token (--[[...]]).
ParseResultThe result of parsing a Luau script, containing the root block, EOF token, and source location info.
SingleLineCommentA single-line comment trivia token (--).
SpanA source location range, defined by begin and end line/column positions.
TriviaTrivia attached to a token: whitespace or comments.
TypeA resolved Luau type, as returned by typeofModule.
TypePackA resolved Luau type pack, as returned by typeofModule.
WhitespaceA whitespace trivia token.
compileCompiles Luau source to bytecode.
loadLoads bytecode into a callable function. chunkname names the chunk for error messages. An optional env table can override the global environment.
parseParses source as a Luau script and returns the resulting CST.
parseExprParses source as a single Luau expression and returns the resulting CST node.
resolveModuleResolves the require path path relative to fromchunkname, returning the absolute path.
span.createCreates a Span from a table with beginLine, beginColumn, endLine, and endColumn.
typeofModuleReturns the type pack representing the return types of the module at modulepath, or nil if unavailable.

Types

Bytecode

Compiled Luau bytecode produced by luau.compile.

luau
type Bytecode = { bytecode: string }

CstAttribute

A function attribute node (@checked, @native, or @deprecated).

luau
type CstAttribute = {
	read location: Span,
	read kind: "attribute",
	read name: CstToken<"@checked" | "@native" | "@deprecated">,
}

CstElseIfExpr

An elseif clause in an if-else expression.

luau
type CstElseIfExpr = {
	read elseIfKeyword: CstToken<"elseif">,
	read condition: CstExpr,
	read thenKeyword: CstToken<"then">,
	read thenExpr: CstExpr,
}

CstElseIfStat

An elseif clause in an if statement.

luau
type CstElseIfStat = {
	read elseIfKeyword: CstToken<"elseif">,
	read condition: CstExpr,
	read thenKeyword: CstToken<"then">,
	read thenBlock: CstStatBlock,
}

CstEof

The end-of-file token.

luau
type CstEof = CstToken<""> & { read tag: "eof" }

CstExpr

Union of all expression node types in the Luau CST.

luau
type CstExpr =

CstExprBinary

A binary expression node (e.g., a + b).

luau
type CstExprBinary = {
	read location: Span,
	read kind: "expr",
	read tag: "binary",
	read lhsOperand: CstExpr,
	read operator: CstToken,
	read rhsOperand: CstExpr,
}

CstExprCall

A function call expression node.

luau
type CstExprCall = {
	read location: Span,
	read kind: "expr",
	read tag: "call",
	read func: CstExpr,
	read openParens: CstToken<"(">?,
	read arguments: Punctuated<CstExpr>,
	read closeParens: CstToken<")">?,
	read self: boolean,
	read argLocation: Span,
}

CstExprConstantBool

A boolean literal node (true or false).

luau
type CstExprConstantBool = {
	read location: Span,
	read kind: "expr",
	read tag: "boolean",
	read value: boolean,
	read token: CstToken<"true" | "false">,
}

CstExprConstantInteger

An integer literal node.

luau
type CstExprConstantInteger = {
	read location: Span,
	read kind: "expr",
	read tag: "integer",
	read value: number,
	read token: CstToken<string>,
}

CstExprConstantNil

A nil literal node.

luau
type CstExprConstantNil = {
	read location: Span,
	read kind: "expr",
	read tag: "nil",
	read token: CstToken<"nil">,
}

CstExprConstantNumber

A number literal node.

luau
type CstExprConstantNumber = {
	read location: Span,
	read kind: "expr",
	read tag: "number",
	read value: number,
	read token: CstToken<string>,
}

CstExprConstantString

A string literal node.

luau
type CstExprConstantString = {
	read location: Span,
	read kind: "expr",
	read tag: "string",
	read quoteStyle: "single" | "double" | "block" | "interp",
	read blockDepth: number,
	read value: CstToken<string>,
}

CstExprFunction

An anonymous function expression node.

luau
type CstExprFunction = {
	read location: Span,
	read kind: "expr",
	read tag: "function",
	read attributes: { CstAttribute },
	read functionKeyword: CstToken<"function">,
	read openGenerics: CstToken<"<">?,
	read generics: Punctuated<CstGenericType>?,
	read genericPacks: Punctuated<CstGenericTypePack>?,
	read closeGenerics: CstToken<">">?,
	read openParens: CstToken<"(">,
	read self: CstLocal?,
	read parameters: Punctuated<CstLocal>,
	read vararg: CstToken<"...">?,
	read varargColon: CstToken<":">?,
	read varargAnnotation: CstTypePack?,
	read closeParens: CstToken<")">,
	read returnSpecifier: CstToken<":">?,
	read returnAnnotation: CstTypePack?,
	read body: CstStatBlock,
	read endKeyword: CstToken<"end">,
}

CstExprGlobal

A reference to a global variable.

luau
type CstExprGlobal = { read location: Span, read kind: "expr", read tag: "global", read name: CstToken }

CstExprGroup

A parenthesized expression node.

luau
type CstExprGroup = {
	read location: Span,
	read kind: "expr",
	read tag: "group",
	read openParens: CstToken<"(">,
	read expression: CstExpr,
	read closeParens: CstToken<")">,
}

CstExprIfElse

An if-else expression node.

luau
type CstExprIfElse = {
	read location: Span,
	read kind: "expr",
	read tag: "conditional",
	read ifKeyword: CstToken<"if">,
	read condition: CstExpr,
	read thenKeyword: CstToken<"then">,
	read thenExpr: CstExpr,
	read elseifs: { CstElseIfExpr },
	read elseKeyword: CstToken<"else">,
	read elseExpr: CstExpr,
}

CstExprIndexExpr

A bracketed index expression node (e.g., t[k]).

luau
type CstExprIndexExpr = {
	read location: Span,
	read kind: "expr",
	read tag: "index",
	read expression: CstExpr,
	read openBrackets: CstToken<"[">,
	read index: CstExpr,
	read closeBrackets: CstToken<"]">,
}

CstExprIndexName

A dot or colon index expression node (e.g., t.k or t:method).

luau
type CstExprIndexName = {
	read location: Span,
	read kind: "expr",
	read tag: "indexname",
	read expression: CstExpr,
	read accessor: CstToken<"." | ":">,
	read index: CstToken<string>,
	read indexLocation: Span,
}

CstExprInstantiate

An explicit generic instantiation expression node (e.g., f<<T>>).

luau
type CstExprInstantiate = {
	read location: Span,
	read kind: "expr",
	read tag: "instantiate",
	read expr: CstExpr,
	read leftArrow1: CstToken<"<">,
	read leftArrow2: CstToken<"<">,
	read typeArguments: Punctuated<CstType | CstTypePack>,
	read rightArrow1: CstToken<">">,
	read rightArrow2: CstToken<">">,
}

CstExprInterpString

An interpolated string expression node (e.g., `hello {name}`).

luau
type CstExprInterpString = {
	read location: Span,
	read kind: "expr",
	read tag: "interpolatedstring",
	read strings: { CstToken<string> },
	read expressions: { CstExpr },
}

CstExprLocal

A reference to a local variable.

luau
type CstExprLocal = {
	read location: Span,
	read kind: "expr",
	read tag: "local",
	read token: CstToken<string>,
	read ["local"]: CstLocal,
	read upvalue: boolean,
}

CstExprTable

A table constructor expression node.

luau
type CstExprTable = {
	read location: Span,
	read kind: "expr",
	read tag: "table",
	read openBrace: CstToken<"{">,
	read entries: { CstTableExprItem },
	read closeBrace: CstToken<"}">,
}

CstExprTypeAssertion

A type assertion expression node (e.g., x :: T).

luau
type CstExprTypeAssertion = {
	read location: Span,
	read kind: "expr",
	read tag: "cast",
	read operand: CstExpr,
	read operator: CstToken<"::">,
	read annotation: CstType,
}

CstExprUnary

A unary expression node (e.g., not x, -x, #x).

luau
type CstExprUnary = {
	read location: Span,
	read kind: "expr",
	read tag: "unary",
	read operator: CstToken<"not" | "-" | "#">,
	read operand: CstExpr,
}

CstExprVarargs

A varargs expression node (...).

luau
type CstExprVarargs = {
	read location: Span,
	read kind: "expr",
	read tag: "vararg",
	read token: CstToken<"...">,
}

CstFunctionTypeParameter

A parameter in a function type annotation.

luau
type CstFunctionTypeParameter = {
	read location: Span,
	read name: CstToken?,
	read colon: CstToken<":">?,
	read type: CstType,
}

CstGenericType

A generic type parameter (e.g., T in function f<T>).

luau
type CstGenericType = {
	read tag: "generic",
	read name: CstToken<string>,
	read equals: CstToken<"=">?,
	read default: CstType?,
}

CstGenericTypePack

A generic type pack parameter (e.g., T... in function f<T...>).

luau
type CstGenericTypePack = {
	read tag: "genericpack",
	read name: CstToken<string>,
	read ellipsis: CstToken<"...">,
	read equals: CstToken<"=">?,
	read default: CstTypePack?,
}

CstLocal

A local variable binding site in the CST.

luau
type CstLocal = {
	read location: Span,
	read kind: "local",
	read name: CstToken<string>,
	read colon: CstToken<":">?,
	read annotation: CstType?,
	read shadows: CstLocal?,
}

CstNode

Union of all node types in the Luau CST.

luau
type CstNode = CstExpr | CstStat | CstType | CstTypePack | CstLocal | CstAttribute | CstToken

CstStat

Union of all statement node types in the Luau CST.

luau
type CstStat =

CstStatAssign

An assignment statement node.

luau
type CstStatAssign = {
	read location: Span,
	read kind: "stat",
	read tag: "assign",
	read variables: Punctuated<CstExpr>,
	read equals: CstToken<"=">,
	read values: Punctuated<CstExpr>,
}

CstStatBlock

A block statement node (a sequence of statements).

luau
type CstStatBlock = {
	read location: Span,
	read kind: "stat",
	read tag: "block",
	read statements: { CstStat },
}

CstStatBreak

A break statement node.

luau
type CstStatBreak = { read location: Span, read kind: "stat", read tag: "break", read token: CstToken<"break"> }

CstStatCompoundAssign

A compound assignment statement node (e.g., x += 1).

luau
type CstStatCompoundAssign = {
	read location: Span,
	read kind: "stat",
	read tag: "compoundassign",
	read variable: CstExpr,
	read operand: CstToken, -- TODO: Enforce token type
	read value: CstExpr,
}

CstStatConst

A const variable declaration statement node.

luau
type CstStatConst = {
	read location: Span,
	read kind: "stat",
	read tag: "const",
	read constKeyword: CstToken<"const">,
	read variables: Punctuated<CstLocal>,
	read equals: CstToken<"=">?,
	read values: Punctuated<CstExpr>,
}

CstStatContinue

A continue statement node.

luau
type CstStatContinue = {
	read location: Span,
	read kind: "stat",
	read tag: "continue",
	read token: CstToken<"continue">,
}

CstStatDo

A do...end block statement node.

luau
type CstStatDo = {
	read location: Span,
	read kind: "stat",
	read tag: "do",
	read doKeyword: CstToken<"do">,
	read body: CstStatBlock,
	read endKeyword: CstToken<"end">,
}

CstStatExpr

A statement consisting of a bare expression (e.g., a function call used as a statement).

luau
type CstStatExpr = {
	read location: Span,
	read kind: "stat",
	read tag: "expression",
	read expression: CstExpr,
}

CstStatFor

A numeric for loop statement node.

luau
type CstStatFor = {
	read location: Span,
	read kind: "stat",
	read tag: "for",
	read forKeyword: CstToken<"for">,
	read variable: CstLocal,
	read equals: CstToken<"=">,
	read from: CstExpr,
	read toComma: CstToken<",">,
	read to: CstExpr,
	read stepComma: CstToken<",">?,
	read step: CstExpr?,
	read doKeyword: CstToken<"do">,
	read body: CstStatBlock,
	read endKeyword: CstToken<"end">,
}

CstStatForIn

A generic for...in loop statement node.

luau
type CstStatForIn = {
	read location: Span,
	read kind: "stat",
	read tag: "forin",
	read forKeyword: CstToken<"for">,
	read variables: Punctuated<CstLocal>,
	read inKeyword: CstToken<"in">,
	read values: Punctuated<CstExpr>,
	read doKeyword: CstToken<"do">,
	read body: CstStatBlock,
	read endKeyword: CstToken<"end">,
}

CstStatFunction

A function declaration statement node.

luau
type CstStatFunction = {
	read location: Span,
	read kind: "stat",
	read tag: "function",
	read name: CstExpr,
	read func: CstExprFunction,
}

CstStatIf

An if...then...elseif...else...end statement node.

luau
type CstStatIf = {
	read location: Span,
	read kind: "stat",
	read tag: "conditional",
	read ifKeyword: CstToken<"if">,
	read condition: CstExpr,
	read thenKeyword: CstToken<"then">,
	read thenBlock: CstStatBlock,
	read elseifs: { CstElseIfStat },
	read elseKeyword: CstToken<"else">?, -- TODO: This could be elseif!
	read elseBlock: CstStatBlock?,
	read endKeyword: CstToken<"end">,
}

CstStatLocal

A local variable declaration statement node.

luau
type CstStatLocal = {
	read location: Span,
	read kind: "stat",
	read tag: "local",
	read localKeyword: CstToken<"local">,
	read variables: Punctuated<CstLocal>,
	read equals: CstToken<"=">?,
	read values: Punctuated<CstExpr>,
}

CstStatLocalFunction

A local function declaration statement node.

luau
type CstStatLocalFunction = {
	read location: Span,
	read kind: "stat",
	read tag: "localfunction",
	read localKeyword: CstToken<"local">,
	read name: CstLocal,
	read func: CstExprFunction,
}

CstStatRepeat

A repeat...until loop statement node.

luau
type CstStatRepeat = {
	read location: Span,
	read kind: "stat",
	read tag: "repeat",
	read repeatKeyword: CstToken<"repeat">,
	read body: CstStatBlock,
	read untilKeyword: CstToken<"until">,
	read condition: CstExpr,
}

CstStatReturn

A return statement node.

luau
type CstStatReturn = {
	read location: Span,
	read kind: "stat",
	read tag: "return",
	read returnKeyword: CstToken<"return">,
	read expressions: Punctuated<CstExpr>,
}

CstStatTypeAlias

A type alias declaration statement node.

luau
type CstStatTypeAlias = {
	read location: Span,
	read kind: "stat",
	read tag: "typealias",
	read export: CstToken<"export">?,
	read typeToken: CstToken<"type">,
	read name: CstToken,
	read openGenerics: CstToken<"<">?,
	read generics: Punctuated<CstGenericType>?,
	read genericPacks: Punctuated<CstGenericTypePack>?,
	read closeGenerics: CstToken<">">?,
	read equals: CstToken<"=">,
	read type: CstType,
}

CstStatTypeFunction

A type function declaration statement node.

luau
type CstStatTypeFunction = {
	read location: Span,
	read kind: "stat",
	read tag: "typefunction",
	read export: CstToken<"export">?,
	read type: CstToken<"type">,
	read name: CstToken,
	read body: CstExprFunction,
}

CstStatWhile

A while...do...end loop statement node.

luau
type CstStatWhile = {
	read location: Span,
	read kind: "stat",
	read tag: "while",
	read whileKeyword: CstToken<"while">,
	read condition: CstExpr,
	read doKeyword: CstToken<"do">,
	read body: CstStatBlock,
	read endKeyword: CstToken<"end">,
}

CstTableExprGeneralItem

A table constructor entry with a computed key (e.g., [expr] = value).

luau
type CstTableExprGeneralItem = {
	read location: Span,
	read kind: "general",
	read indexerOpen: CstToken<"[">,
	read key: CstExpr,
	read indexerClose: CstToken<"]">,
	read equals: CstToken<"=">,
	read value: CstExpr,
	read separator: CstToken<"," | ";">?,
	read isTableItem: true,
}

CstTableExprItem

Union of all table constructor entry types.

luau
type CstTableExprItem = CstTableExprListItem | CstTableExprRecordItem | CstTableExprGeneralItem

CstTableExprListItem

A positional table constructor entry (e.g., value in { value }).

luau
type CstTableExprListItem = {
	read location: Span,
	read kind: "list",
	read value: CstExpr,
	read separator: CstToken<"," | ";">?,
	read isTableItem: true,
}

CstTableExprRecordItem

A named table constructor entry (e.g., key = value).

luau
type CstTableExprRecordItem = {
	read location: Span,
	read kind: "record",
	read key: CstToken<string>,
	read equals: CstToken<"=">,
	read value: CstExpr,
	read separator: CstToken<"," | ";">?,
	read isTableItem: true,
}

CstTableTypeItem

Union of all table type entry kinds.

luau
type CstTableTypeItem = CstTableTypeItemIndexer | CstTableTypeItemStringProperty | CstTableTypeItemProperty

CstTableTypeItemIndexer

A computed-key indexer entry in a table type (e.g., [K]: V).

luau
type CstTableTypeItemIndexer = {
	read kind: "indexer",
	read access: CstToken<"read" | "write">?,
	read indexerOpen: CstToken<"[">,
	read key: CstType,
	read indexerClose: CstToken<"]">,
	read colon: CstToken<":">,
	read value: CstType,
	read separator: CstToken<"," | ";">?,
}

CstTableTypeItemProperty

A named property entry in a table type (e.g., key: T).

luau
type CstTableTypeItemProperty = {
	read kind: "property",
	read access: CstToken<"read" | "write">?,
	read key: CstToken,
	read colon: CstToken<":">,
	read value: CstType,
	read separator: CstToken<"," | ";">?,
}

CstTableTypeItemStringProperty

A string-literal-keyed property entry in a table type (e.g., ["key"]: T).

luau
type CstTableTypeItemStringProperty = {
	read kind: "stringproperty",
	read access: CstToken<"read" | "write">?,
	read indexerOpen: CstToken<"[">,
	read key: CstTypeSingletonString,
	read indexerClose: CstToken<"]">,
	read colon: CstToken<":">,
	read value: CstType,
	read separator: CstToken<"," | ";">?,
}

CstType

Union of all type annotation node types in the Luau CST.

luau
type CstType =

CstTypeArray

An array type annotation node (e.g., { T }).

luau
type CstTypeArray = {
	read location: Span,
	read kind: "type",
	read tag: "array",
	read openBrace: CstToken<"{">,
	read access: CstToken<"read" | "write">?,
	read type: CstType,
	read closeBrace: CstToken<"}">,
}

CstTypeFunction

A function type annotation node.

luau
type CstTypeFunction = {
	read location: Span,
	read kind: "type",
	read tag: "function",
	read openGenerics: CstToken<"<">?,
	read generics: Punctuated<CstGenericType>?,
	read genericPacks: Punctuated<CstGenericTypePack>?,
	read closeGenerics: CstToken<">">?,
	read openParens: CstToken<"(">,
	read parameters: Punctuated<CstFunctionTypeParameter>,
	read vararg: CstTypePack?,
	read closeParens: CstToken<")">,
	read returnArrow: CstToken<"->">,
	read returnTypes: CstTypePack,
}

CstTypeGroup

A parenthesized type annotation node.

luau
type CstTypeGroup = {
	read location: Span,
	read kind: "type",
	read tag: "group",
	read openParens: CstToken<"(">,
	read type: CstType,
	read closeParens: CstToken<")">,
}

CstTypeIntersection

An intersection type annotation node (e.g., A & B).

luau
type CstTypeIntersection = {
	read location: Span,
	read kind: "type",
	read tag: "intersection",
	read leading: CstToken<"&">?,
	read types: Punctuated<CstType, "&">,
}

CstTypeOptional

An optional type annotation node (e.g., T?).

luau
type CstTypeOptional =

CstTypePack

Union of all type pack annotation node types in the Luau CST.

luau
type CstTypePack = CstTypePackExplicit | CstTypePackGeneric | CstTypePackVariadic

CstTypePackExplicit

An explicit type pack annotation node (e.g., (T, U)).

luau
type CstTypePackExplicit = {
	read location: Span,
	read kind: "typepack",
	read tag: "explicit",
	read openParens: CstToken<"(">?,
	read types: Punctuated<CstType>,
	read tailType: CstTypePack?,
	read closeParens: CstToken<")">?,
}

CstTypePackGeneric

A generic type pack annotation node (e.g., T...).

luau
type CstTypePackGeneric = {
	read location: Span,
	read kind: "typepack",
	read tag: "generic",
	read name: CstToken,
	read ellipsis: CstToken<"...">,
}

CstTypePackVariadic

A variadic type pack annotation node (e.g., ...T).

luau
type CstTypePackVariadic = {
	read location: Span,
	read kind: "typepack",
	read tag: "variadic",
	--- May be nil when present as the vararg annotation in a function body
	read ellipsis: CstToken<"...">?,
	read type: CstType,
}

CstTypeReference

A named type reference node (e.g., string, MyType<T>).

luau
type CstTypeReference = {
	read location: Span,
	read kind: "type",
	read tag: "reference",
	read prefix: CstToken<string>?,
	read prefixPoint: CstToken<".">?,
	read name: CstToken<string>,
	read openParameters: CstToken<"<">?,
	read parameters: Punctuated<CstType | CstTypePack>?,
	read closeParameters: CstToken<">">?,
}

CstTypeSingletonBool

A boolean singleton type node (true or false).

luau
type CstTypeSingletonBool = {
	read location: Span,
	read kind: "type",
	read tag: "boolean",
	read value: boolean,
	read token: CstToken<"true" | "false">,
}

CstTypeSingletonString

A string singleton type node (e.g., "hello").

luau
type CstTypeSingletonString = {
	read location: Span,
	read kind: "type",
	read tag: "string",
	read quoteStyle: "single" | "double",
	read value: CstToken<string>,
}

CstTypeTable

A table type annotation node.

luau
type CstTypeTable = {
	read location: Span,
	read kind: "type",
	read tag: "table",
	read openBrace: CstToken<"{">,
	read entries: { CstTableTypeItem },
	read closeBrace: CstToken<"}">,
}

CstTypeTypeof

A typeof(expr) type annotation node.

luau
type CstTypeTypeof = {
	read location: Span,
	read kind: "type",
	read tag: "typeof",
	read typeof: CstToken<"typeof">,
	read openParens: CstToken<"(">,
	read expression: CstExpr,
	read closeParens: CstToken<")">,
}

CstTypeUnion

A union type annotation node (e.g., A | B).

luau
type CstTypeUnion = {
	read location: Span,
	read kind: "type",
	read tag: "union",
	read leading: CstToken<"|">?,
	-- Separator may be nil for CstTypeOptional
	read types: Punctuated<CstType, "|">,
}

MultiLineComment

A multi-line block comment trivia token (--[[...]]).

luau
type MultiLineComment = {
	read tag: "blockcomment",
	read location: Span,
	read text: string,
	-- TODO: depth: number,
}

ParseResult

The result of parsing a Luau script, containing the root block, EOF token, and source location info.

luau
type ParseResult = {
	read root: CstStatBlock,
	read eof: CstEof,
	read lines: number,
	read lineOffsets: { number },
}

SingleLineComment

A single-line comment trivia token (--).

luau
type SingleLineComment = {
	read tag: "comment",
	read location: Span,
	read text: string,
}

Span

A source location range, defined by begin and end line/column positions.

luau
type Span = setmetatable<SpanData, SpanMT>

Trivia

Trivia attached to a token: whitespace or comments.

luau
type Trivia = Whitespace | SingleLineComment | MultiLineComment

Type

A resolved Luau type, as returned by typeofModule.

luau
type Type = {
	tag: "nil"
		| "unknown"
		| "never"
		| "any"
		| "boolean"
		| "number"
		| "string"
		| "buffer"
		| "thread"
		| "singleton"
		| "negation"
		| "union"
		| "intersection"
		| "table"
		| "function"
		| "extern"
		| "generic",

	-- for singleton type
	value: string | boolean | nil,

	-- for negation type
	inner: Type,

	-- for union and intersection types
	components: { Type },

	-- for table type
	properties: { [string]: { read: Type?, write: Type? } },
	indexer: { index: Type }?, -- TODO: add readresult and writeresult
	-- TODO: readindexer: { index: type, result: type } }?,

TypePack

A resolved Luau type pack, as returned by typeofModule.

luau
type TypePack = {
	tag: "typepack" | "variadic" | "generic",
	head: { Type }?,
	tail: TypePack?,

	-- for variadic type packs
	type: Type,
	hidden: boolean,

	-- for generic type packs
	name: string,
	ispack: boolean,
}

Whitespace

A whitespace trivia token.

luau
type Whitespace = {
	read tag: "whitespace",
	read location: Span,
	read text: string,
}

Functions and Properties

luau.compile

Compiles Luau source to bytecode.

luau
(source: string) -> Bytecode

luau.load

Loads bytecode into a callable function. chunkname names the chunk for error messages. An optional env table can override the global environment.

luau
(bytecode: Bytecode, chunkname: string, env: { [any]: any }?) -> (...any) -> ...any

luau.parse

Parses source as a Luau script and returns the resulting CST.

luau
(source: string) -> ParseResult

luau.parseExpr

Parses source as a single Luau expression and returns the resulting CST node.

luau
(source: string) -> CstExpr

luau.resolveModule

Resolves the require path path relative to fromchunkname, returning the absolute path.

luau
(path: string, fromchunkname: string) -> string

luau.span.create

Creates a Span from a table with beginLine, beginColumn, endLine, and endColumn.

luau
(tbl: { beginLine: number, beginColumn: number, endLine: number, endColumn: number }) -> Span

luau.typeofModule

Returns the type pack representing the return types of the module at modulepath, or nil if unavailable.

luau
(modulepath: string) -> TypePack?