Ouro
Types
NodeId type
type NodeId = numberListId type
type ListId = numberSymbolId type
type SymbolId = numberBindingId type
type BindingId = numberGrammarFlags type
type GrammarFlags = { [string]: boolean }ResolvedFlags type
type ResolvedFlags = { [string]: boolean }ParseOptions type
type ParseOptions = {
profile: ("upstream" | "studio" | "experimental" | GrammarFlags)?, -- grammar profile name or explicit flag map
lossless: boolean?, -- retain compact token/trivia tape for `reconstruct()`
captureComments: boolean?, -- collect comments separately (auto-enabled by `lossless`)
allowDeclarationSyntax: boolean?, -- enable `.d.luau` `declare` syntax
requireEOF: boolean?, -- require trailing EOF on fragment entrypoints
noErrorLimit: boolean?, -- disable `errorLimit` cap when `true`
recursionLimit: number?, -- maximum nested parser recursion depth (default `1,000`)
typeLengthLimit: number?, -- maximum items in a type list or union/intersection chain (default `1,000`)
errorLimit: number?, -- maximum diagnostics before aborting with `"limit"` (default `100`)
checkpointInterval: number?, -- scanned byte interval between `checkpoint` calls (default `4,096`)
checkpoint: ((offset: number) -> boolean?)?, -- cooperative yield or cancel callback (`false` cancels)
}Configuration options for Ouro.parse, parseExpression, parseType, and newContext.
Diagnostic type
type Diagnostic = { start: number, finish: number, message: string, code: "syntax" | "limit" | "compile" }Comment type
type Comment = { kind: number, start: number, finish: number }HotComment type
type HotComment = { header: boolean, content: string, start: number, finish: number }TokenTape type
type TokenTape = { kinds: { number }, starts: { number }, finishes: { number }, count: number }AstTable type
type AstTable = { [string]: any }AstVisitor type
type AstVisitor = {
enter: ((nodeId: NodeId, kind: number, depth: number) -> boolean?)?,
leave: ((nodeId: NodeId, kind: number, depth: number) -> ())?,
}Visitor callbacks for ParseResult:visit. Return false from enter to skip child traversal.
Node type
type Node = { kind: number, start: number, finish: number, [string]: any }Binding type
type Binding = {
name: SymbolId,
start: number,
finish: number,
annotation: NodeId,
shadow: BindingId,
functionDepth: number,
loopDepth: number,
scopeDepth: number,
isConst: boolean,
isExported: boolean,
}Arena type
type Arena = {
nodes: { Node },
kinds: { number },
starts: { number },
finishes: { number },
hasTypeAnnotations: boolean,
hasClasses: boolean,
listFirsts: { number },
listCounts: { number },
listValues: { any },
bindings: { Binding },
symbols: { string },
kind: (Arena, NodeId) -> number,
kindName: (Arena, NodeId) -> string,
listCount: (Arena, ListId) -> number,
listAt: (Arena, ListId, number) -> any,
listItems: (Arena, ListId) -> { any },
}Read-only AST arena returned on ParseResult.arena.
ParseResult type
type ParseResult = {
status: "ok" | "syntaxError" | "limit" | "cancelled", -- parse outcome (`root == 0` on `"limit"` or `"cancelled"`)
root: NodeId, -- root AST node ID (`0` if aborted)
arena: Arena, -- flat SoA + record AST arena owned by this result
source: string, -- original source string passed to the parser
diagnostics: { Diagnostic }, -- reported syntax, limit, or compile errors
lineStarts: { number }, -- zero-based byte offsets where each LF-delimited line starts
comments: { Comment }, -- captured comments when `captureComments` or `lossless` is enabled
hotcomments: { HotComment }, -- parsed `--!` / header hotcomments
tape: TokenTape?, -- lossless lexical tape when `lossless = true`
profile: "upstream" | "studio" | "experimental" | "custom", -- resolved grammar profile name
flags: ResolvedFlags, -- frozen grammar boolean map active during the parse
kind: (ParseResult, NodeId) -> number,
kindName: (ParseResult, NodeId) -> string,
range: (ParseResult, NodeId) -> (number, number),
position: (ParseResult, number) -> (number, number),
offset: (ParseResult, number, number) -> number,
childCount: (ParseResult, NodeId) -> number,
childAt: (ParseResult, NodeId, number) -> NodeId,
forEachChild: (ParseResult, NodeId, (NodeId) -> boolean?) -> (),
visit: (ParseResult, AstVisitor | ((NodeId, number, number) -> boolean?)) -> (),
reconstruct: (ParseResult) -> string,
}Structured result returned by Ouro.parse, parseExpression, and parseType.
ParserContext type
type ParserContext = {
busy: boolean, -- true while a parse (possibly suspended at a checkpoint) is active
options: ParseOptions,
reset: (ParserContext) -> (),
parse: (ParserContext, string) -> ParseResult,
parseExpression: (ParserContext, string) -> ParseResult,
parseType: (ParserContext, string) -> ParseResult,
}Reusable parser context that recycles internal scratch tables across calls.
CompileConstant type
type CompileConstant = { type: "nil" }
| { type: "boolean", value: boolean }
| { type: "number", value: number }
| { type: "vectorf", value: { number } }
| { type: "vectord", value: { number } }
| { type: "string", value: string }
| { type: "table", value: { [string]: CompileConstant } }ProtoTableConstant type
type ProtoTableConstant = {
keys: { number },
constants: { number }?,
length: number,
}ProtoClassConstant type
type ProtoClassConstant = {
className: number,
numPrivateInstanceProps: number,
numPrivateStaticProps: number,
propertyNames: { number },
methodNames: { number },
}Proto type
type Proto = {
id: number,
maxstacksize: number,
numparams: number,
nups: number,
isvararg: boolean,
flags: number,
code: { number },
kTypes: { number },
kValues: { any },
p: { number },
linedefined: number,
debugname: string?,
lineData: string?,
linegaplog2: number?,
locvars: { { varname: string?, startpc: number, endpc: number, reg: number } }?,
upvalues: { string? }?,
typeinfo: string?,
}ProtoModule type
type ProtoModule = {
version: number,
typesversion: number,
strings: { string },
protos: { Proto },
mainid: number,
userdataTypes: { string }?,
}In-memory decoded bytecode module produced by Bytecode.deserialize and Compiler.compileProto.
BytecodeEncoder type
type BytecodeEncoder = ((number) -> number) | { encode: (self: any, code: { number }) -> () }BytecodeDecoder type
type BytecodeDecoder = ((number) -> number) | { decode: (self: any, code: { number }) -> () }CompileOptions type
type CompileOptions = {
optimizationLevel: number?, -- `0` = none, `1` = baseline folding & fastcalls (default), `2` = inlining & unrolling
debugLevel: number?, -- `0` = stripped, `1` = line info & function names (default), `2` = locals & upvalues
typeInfoLevel: number?, -- `0` = annotated functions only (default), `1` = all functions
coverageLevel: number?, -- `0` = disabled (default), `1` = statements, `2` = statements & expressions
vectorLib: string?, -- global library name for vector constructor lowering (e.g. `"Vector3"`)
vectorCtor: string?, -- constructor member name on `vectorLib` (e.g. `"new"`)
vectorType: string?, -- vector annotation name used for typed local specialization
vectorPrecision: number?, -- `0` = 32-bit float vectors (default), `1` = 64-bit doubles
mutableGlobals: { string }?, -- globals excluded from immutable builtin optimization
userdataTypes: { string }?, -- known host userdata type names for type-info emission
librariesWithKnownMembers: { string }?, -- library names eligible for `libraryMember*Cb` callbacks
libraryMemberTypeCb: ((library: string, member: string) -> number)?, -- returns `Ouro.Bytecode.Types` tag (`0..255`)
libraryMemberConstantCb: ((library: string, member: string) -> CompileConstant?)?,
disabledBuiltins: { string }?, -- builtin names or wildcards (`"math.*"`, `"*"`) excluded from fastcalls
encoder: BytecodeEncoder?, -- custom instruction opcode encoder for serialized bytecode
dumpFlags: number?, -- bitmask of `Ouro.Bytecode.DumpFlags` for remarks and disassembly dumps
flags: { [string]: boolean | number }?, -- overrides matching `Ouro.Compiler.CompilerFlags`
parseOptions: ParseOptions?, -- forwarded to the parser when input is source text
}Configuration options for Ouro.compile, Ouro.compileResult, and Ouro.Compiler.compileProto.
BytecodeBuilder type
type BytecodeBuilder = {
getBytecode: (self: BytecodeBuilder) -> string,
toProtoModule: (self: BytecodeBuilder) -> ProtoModule,
setDumpSource: (self: BytecodeBuilder, source: string) -> (),
dumpFunction: (self: BytecodeBuilder, fid: number) -> string,
dumpEverything: (self: BytecodeBuilder) -> string,
dumpSourceRemarks: (self: BytecodeBuilder) -> string,
dumpTypeInfo: (self: BytecodeBuilder) -> string,
}Mutable bytecode builder returned on CompileResult.builder.
ResourceLimits type
type ResourceLimits = {
maxStringLength: number?, -- maximum string byte length produced by stdlib calls or `CONCAT`
maxTableSize: number?, -- maximum element count in constructors (`table.create`, `NEWTABLE`, `SETLIST`)
maxBufferSize: number?, -- maximum buffer size allocated through `buffer` helpers
maxPatternLength: number?, -- maximum pattern length passed to `string.find`/`match`/`gmatch`/`gsub`
}Opt-in allocation and pattern caps enforced by VM standard libraries and constructors.
EnvironmentOptions type
type EnvironmentOptions = {
inheritHost: boolean?, -- inherit non-standard host or Roblox globals (defaults `false`, excludes `script` and `loadstring`)
libraries: { string }?, -- stdlib allowlist (`"base"`, `"bit32"`, `"buffer"`, `"coroutine"`, `"debug"`, `"math"`, `"os"`, `"string"`, `"table"`, `"utf8"`, `"vector"`)
readOnly: boolean?, -- freeze environment or wrap host inheritance in a locked read-only proxy
resourceLimits: ResourceLimits?, -- opt-in stdlib and constructor caps (`nil` for zero overhead)
}Configuration options for Ouro.VM.createEnvironment.
DebugFrameInfo type
type DebugFrameInfo = {
source: string,
line: number,
name: string?,
numparams: number,
isvararg: boolean,
depth: number,
}Frame snapshot passed to LoadOptions debug callbacks (onCall, onReturn, onLine, onBreak).
CoverageEntry type
type CoverageEntry = {
name: string?,
lineDefined: number,
hits: { [number]: number },
totalHits: number,
}Per-function line execution counts returned by Ouro.VM.getCoverage.
UpvalueInfo type
type UpvalueInfo = {
index: number,
name: string?,
value: any,
}Captured upvalue metadata returned by Ouro.VM.getUpvalues.
LoadMode type
type LoadMode = "text" | "binary" | "auto"LoadOptions type
type LoadOptions = {
name: string?, -- chunk name for stack traces (`"=chunk"` for binary inputs, `[string "..."]` for text)
env: { [any]: any }?, -- custom global environment (defaults to a fresh isolated `VM.createEnvironment()`)
compile: CompileOptions?, -- compiler options when loading text source chunks
decoder: BytecodeDecoder?, -- reverses a custom `CompileOptions.encoder` on binary bytecode
mode: LoadMode?, -- `"text"`, `"binary"`, or `"auto"` header sniffing (defaults `"text"` for strings, `"binary"` for buffers)
timeout: number?, -- lazy wall-clock deadline in seconds (`os.clock()`) started on first invocation
instructionLimit: number?, -- maximum VM instructions executed before aborting
callLimit: number?, -- maximum active guest call frames across nested calls and coroutines
interruptInterval: number?, -- instruction interval between `interrupt` and `timeout` checks (default `4,096`)
interrupt: (() -> boolean?)?, -- periodic callback; return `false`, yield, or error to abort execution
getGlobal: ((name: string, env: { [any]: any }) -> any)?, -- intercepts global reads (`GETGLOBAL`, unresolved `GETIMPORT`, `_G[k]`)
setGlobal: ((name: string, value: any, env: { [any]: any }) -> ())?, -- intercepts global writes (`SETGLOBAL`, `_G[k] = v`)
safeEnv: boolean?, -- preserve fast paths on unmodified built-in roots present in `env` alongside `getGlobal`
resourceLimits: ResourceLimits?, -- overrides `env` resource caps for this chunk
onCall: ((info: DebugFrameInfo) -> ())?, -- fires when entering a VM closure frame
onReturn: ((info: DebugFrameInfo) -> ())?, -- fires before exiting a VM closure frame
onLine: ((line: number, info: DebugFrameInfo) -> ())?, -- fires when execution advances to a different source line
onBreak: ((line: number, info: DebugFrameInfo) -> ())?, -- fires on `LOP_BREAK` instructions
}Execution environment, resource budget, global hook, and debug hook options for Ouro.load.
CompileResult type
type CompileResult = {
status: "ok" | "parseError" | "compileError",
bytecode: string, -- compiled bytecode, or status-zero encoded error readable via `Bytecode.decodeError`
builder: BytecodeBuilder?,
error: string?,
diagnostics: { Diagnostic },
parseResult: ParseResult,
}Structured result returned by Ouro.compileResult.
Properties
version Read Only
Ouro.version: stringPackage semantic version string.
luauVersion Re-export
Ouro.luauVersionPinned upstream Luau release version ("0.748").
upstreamRevision Re-export
Ouro.upstreamRevisionPinned upstream Luau Git commit SHA from UPSTREAM.json.
Ast Module
Ouro.Ast: AstLossless AST table serializer (Ast.toTables).
Profiles Module
Ouro.Profiles: ProfilesBuilt-in grammar flag profiles (upstream, studio, experimental) and resolver.
Tokens Module
Ouro.Tokens: TokenImmutable map of token names (Eof, Name, ReservedFunction, ...) to numeric token kinds.
Compiler Module
Ouro.Compiler: CompilerBytecode compiler module (compile, compileResult, compileProto, CompilerFlags).
Bytecode Module
Ouro.Bytecode: BytecodeBytecode codec, disassembler, verifier, and instruction tables.
VM Module
Ouro.VM: VMSandboxed register VM, isolated environments, execution limits, and debug hooks.
Functions
parse
Ouro.parse(source: string, options: ParseOptions?): ParseResultParses a Luau source chunk into an arena-backed ParseResult.
parseExpression
Ouro.parseExpression(source: string, options: ParseOptions?): ParseResultParses a standalone Luau expression into an arena-backed ParseResult.
parseType
Ouro.parseType(source: string, options: ParseOptions?): ParseResultParses a standalone Luau type annotation into an arena-backed ParseResult.
newContext
Ouro.newContext(options: ParseOptions?): ParserContextCreates a reusable ParserContext that recycles internal scratch tables across parses.
compile
Ouro.compile(source: string | ParseResult, options: CompileOptions?): (string?, string?)Compiles Luau source or a ParseResult into binary bytecode, returning (bytecode, nil) or (nil, err).
compileResult
Ouro.compileResult(source: string | ParseResult, options: CompileOptions?): CompileResultCompiles Luau source or a ParseResult and returns a structured CompileResult.
load
Ouro.load(chunk: string | buffer | ProtoModule, options: LoadOptions?): (((...any) -> ...any)?, string?)Compiles or deserializes a Luau chunk and loads it into a callable sandboxed VM closure.