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
| Entry | Description |
|---|---|
| Bytecode | Compiled Luau bytecode produced by luau.compile. |
| CstAttribute | A function attribute node (@checked, @native, or @deprecated). |
| CstElseIfExpr | An elseif clause in an if-else expression. |
| CstElseIfStat | An elseif clause in an if statement. |
| CstEof | The end-of-file token. |
| CstExpr | Union of all expression node types in the Luau CST. |
| CstExprBinary | A binary expression node (e.g., a + b). |
| CstExprCall | A function call expression node. |
| CstExprConstantBool | A boolean literal node (true or false). |
| CstExprConstantInteger | An integer literal node. |
| CstExprConstantNil | A nil literal node. |
| CstExprConstantNumber | A number literal node. |
| CstExprConstantString | A string literal node. |
| CstExprFunction | An anonymous function expression node. |
| CstExprGlobal | A reference to a global variable. |
| CstExprGroup | A parenthesized expression node. |
| CstExprIfElse | An if-else expression node. |
| CstExprIndexExpr | A bracketed index expression node (e.g., t[k]). |
| CstExprIndexName | A dot or colon index expression node (e.g., t.k or t:method). |
| CstExprInstantiate | An explicit generic instantiation expression node (e.g., f<<T>>). |
| CstExprInterpString | An interpolated string expression node (e.g., `hello {name}`). |
| CstExprLocal | A reference to a local variable. |
| CstExprTable | A table constructor expression node. |
| CstExprTypeAssertion | A type assertion expression node (e.g., x :: T). |
| CstExprUnary | A unary expression node (e.g., not x, -x, #x). |
| CstExprVarargs | A varargs expression node (...). |
| CstFunctionTypeParameter | A parameter in a function type annotation. |
| CstGenericType | A generic type parameter (e.g., T in function f<T>). |
| CstGenericTypePack | A generic type pack parameter (e.g., T... in function f<T...>). |
| CstLocal | A local variable binding site in the CST. |
| CstNode | Union of all node types in the Luau CST. |
| CstStat | Union of all statement node types in the Luau CST. |
| CstStatAssign | An assignment statement node. |
| CstStatBlock | A block statement node (a sequence of statements). |
| CstStatBreak | A break statement node. |
| CstStatCompoundAssign | A compound assignment statement node (e.g., x += 1). |
| CstStatConst | A const variable declaration statement node. |
| CstStatContinue | A continue statement node. |
| CstStatDo | A do...end block statement node. |
| CstStatExpr | A statement consisting of a bare expression (e.g., a function call used as a statement). |
| CstStatFor | A numeric for loop statement node. |
| CstStatForIn | A generic for...in loop statement node. |
| CstStatFunction | A function declaration statement node. |
| CstStatIf | An if...then...elseif...else...end statement node. |
| CstStatLocal | A local variable declaration statement node. |
| CstStatLocalFunction | A local function declaration statement node. |
| CstStatRepeat | A repeat...until loop statement node. |
| CstStatReturn | A return statement node. |
| CstStatTypeAlias | A type alias declaration statement node. |
| CstStatTypeFunction | A type function declaration statement node. |
| CstStatWhile | A while...do...end loop statement node. |
| CstTableExprGeneralItem | A table constructor entry with a computed key (e.g., [expr] = value). |
| CstTableExprItem | Union of all table constructor entry types. |
| CstTableExprListItem | A positional table constructor entry (e.g., value in { value }). |
| CstTableExprRecordItem | A named table constructor entry (e.g., key = value). |
| CstTableTypeItem | Union of all table type entry kinds. |
| CstTableTypeItemIndexer | A computed-key indexer entry in a table type (e.g., [K]: V). |
| CstTableTypeItemProperty | A named property entry in a table type (e.g., key: T). |
| CstTableTypeItemStringProperty | A string-literal-keyed property entry in a table type (e.g., ["key"]: T). |
| CstType | Union of all type annotation node types in the Luau CST. |
| CstTypeArray | An array type annotation node (e.g., { T }). |
| CstTypeFunction | A function type annotation node. |
| CstTypeGroup | A parenthesized type annotation node. |
| CstTypeIntersection | An intersection type annotation node (e.g., A & B). |
| CstTypeOptional | An optional type annotation node (e.g., T?). |
| CstTypePack | Union of all type pack annotation node types in the Luau CST. |
| CstTypePackExplicit | An explicit type pack annotation node (e.g., (T, U)). |
| CstTypePackGeneric | A generic type pack annotation node (e.g., T...). |
| CstTypePackVariadic | A variadic type pack annotation node (e.g., ...T). |
| CstTypeReference | A named type reference node (e.g., string, MyType<T>). |
| CstTypeSingletonBool | A boolean singleton type node (true or false). |
| CstTypeSingletonString | A string singleton type node (e.g., "hello"). |
| CstTypeTable | A table type annotation node. |
| CstTypeTypeof | A typeof(expr) type annotation node. |
| CstTypeUnion | A union type annotation node (e.g., `A |
| MultiLineComment | A multi-line block comment trivia token (--[[...]]). |
| ParseResult | The result of parsing a Luau script, containing the root block, EOF token, and source location info. |
| SingleLineComment | A single-line comment trivia token (--). |
| Span | A source location range, defined by begin and end line/column positions. |
| Trivia | Trivia attached to a token: whitespace or comments. |
| Type | A resolved Luau type, as returned by typeofModule. |
| TypePack | A resolved Luau type pack, as returned by typeofModule. |
| Whitespace | A whitespace trivia token. |
| compile | Compiles Luau source to bytecode. |
| load | Loads bytecode into a callable function. chunkname names the chunk for error messages. An optional env table can override the global environment. |
| parse | Parses source as a Luau script and returns the resulting CST. |
| parseExpr | Parses source as a single Luau expression and returns the resulting CST node. |
| resolveModule | Resolves the require path path relative to fromchunkname, returning the absolute path. |
| span.create | Creates a Span from a table with beginLine, beginColumn, endLine, and endColumn. |
| typeofModule | Returns 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.
type Bytecode = { bytecode: string }CstAttribute
A function attribute node (@checked, @native, or @deprecated).
type CstAttribute = {
read location: Span,
read kind: "attribute",
read name: CstToken<"@checked" | "@native" | "@deprecated">,
}CstElseIfExpr
An elseif clause in an if-else expression.
type CstElseIfExpr = {
read elseIfKeyword: CstToken<"elseif">,
read condition: CstExpr,
read thenKeyword: CstToken<"then">,
read thenExpr: CstExpr,
}CstElseIfStat
An elseif clause in an if statement.
type CstElseIfStat = {
read elseIfKeyword: CstToken<"elseif">,
read condition: CstExpr,
read thenKeyword: CstToken<"then">,
read thenBlock: CstStatBlock,
}CstEof
The end-of-file token.
type CstEof = CstToken<""> & { read tag: "eof" }CstExpr
Union of all expression node types in the Luau CST.
type CstExpr =CstExprBinary
A binary expression node (e.g., a + b).
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.
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).
type CstExprConstantBool = {
read location: Span,
read kind: "expr",
read tag: "boolean",
read value: boolean,
read token: CstToken<"true" | "false">,
}CstExprConstantInteger
An integer literal node.
type CstExprConstantInteger = {
read location: Span,
read kind: "expr",
read tag: "integer",
read value: number,
read token: CstToken<string>,
}CstExprConstantNil
A nil literal node.
type CstExprConstantNil = {
read location: Span,
read kind: "expr",
read tag: "nil",
read token: CstToken<"nil">,
}CstExprConstantNumber
A number literal node.
type CstExprConstantNumber = {
read location: Span,
read kind: "expr",
read tag: "number",
read value: number,
read token: CstToken<string>,
}CstExprConstantString
A string literal node.
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.
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.
type CstExprGlobal = { read location: Span, read kind: "expr", read tag: "global", read name: CstToken }CstExprGroup
A parenthesized expression node.
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.
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]).
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).
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>>).
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}`).
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.
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.
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).
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).
type CstExprUnary = {
read location: Span,
read kind: "expr",
read tag: "unary",
read operator: CstToken<"not" | "-" | "#">,
read operand: CstExpr,
}CstExprVarargs
A varargs expression node (...).
type CstExprVarargs = {
read location: Span,
read kind: "expr",
read tag: "vararg",
read token: CstToken<"...">,
}CstFunctionTypeParameter
A parameter in a function type annotation.
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>).
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...>).
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.
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.
type CstNode = CstExpr | CstStat | CstType | CstTypePack | CstLocal | CstAttribute | CstTokenCstStat
Union of all statement node types in the Luau CST.
type CstStat =CstStatAssign
An assignment statement node.
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).
type CstStatBlock = {
read location: Span,
read kind: "stat",
read tag: "block",
read statements: { CstStat },
}CstStatBreak
A break statement node.
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).
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.
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.
type CstStatContinue = {
read location: Span,
read kind: "stat",
read tag: "continue",
read token: CstToken<"continue">,
}CstStatDo
A do...end block statement node.
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).
type CstStatExpr = {
read location: Span,
read kind: "stat",
read tag: "expression",
read expression: CstExpr,
}CstStatFor
A numeric for loop statement node.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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).
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.
type CstTableExprItem = CstTableExprListItem | CstTableExprRecordItem | CstTableExprGeneralItemCstTableExprListItem
A positional table constructor entry (e.g., value in { value }).
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).
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.
type CstTableTypeItem = CstTableTypeItemIndexer | CstTableTypeItemStringProperty | CstTableTypeItemPropertyCstTableTypeItemIndexer
A computed-key indexer entry in a table type (e.g., [K]: V).
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).
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).
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.
type CstType =CstTypeArray
An array type annotation node (e.g., { T }).
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.
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.
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).
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?).
type CstTypeOptional =CstTypePack
Union of all type pack annotation node types in the Luau CST.
type CstTypePack = CstTypePackExplicit | CstTypePackGeneric | CstTypePackVariadicCstTypePackExplicit
An explicit type pack annotation node (e.g., (T, U)).
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...).
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).
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>).
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).
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").
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.
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.
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).
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 (--[[...]]).
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.
type ParseResult = {
read root: CstStatBlock,
read eof: CstEof,
read lines: number,
read lineOffsets: { number },
}SingleLineComment
A single-line comment trivia token (--).
type SingleLineComment = {
read tag: "comment",
read location: Span,
read text: string,
}Span
A source location range, defined by begin and end line/column positions.
type Span = setmetatable<SpanData, SpanMT>Trivia
Trivia attached to a token: whitespace or comments.
type Trivia = Whitespace | SingleLineComment | MultiLineCommentType
A resolved Luau type, as returned by typeofModule.
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.
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.
type Whitespace = {
read tag: "whitespace",
read location: Span,
read text: string,
}Functions and Properties
luau.compile
Compiles Luau source to bytecode.
(source: string) -> Bytecodeluau.load
Loads bytecode into a callable function. chunkname names the chunk for error messages. An optional env table can override the global environment.
(bytecode: Bytecode, chunkname: string, env: { [any]: any }?) -> (...any) -> ...anyluau.parse
Parses source as a Luau script and returns the resulting CST.
(source: string) -> ParseResultluau.parseExpr
Parses source as a single Luau expression and returns the resulting CST node.
(source: string) -> CstExprluau.resolveModule
Resolves the require path path relative to fromchunkname, returning the absolute path.
(path: string, fromchunkname: string) -> stringluau.span.create
Creates a Span from a table with beginLine, beginColumn, endLine, and endColumn.
(tbl: { beginLine: number, beginColumn: number, endLine: number, endColumn: number }) -> Spanluau.typeofModule
Returns the type pack representing the return types of the module at modulepath, or nil if unavailable.
(modulepath: string) -> TypePack?