Skip to content

Compiler ​

Bytecode compiler lowering Ouro ParseResult arenas or Luau source strings across optimization levels 0–2.

Types ​

CompileConstant type ​

luau
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 } }

CompileOptions type ​

luau
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.

CompileResult type ​

luau
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 ​

CompilerFlags Re-export ​

luau
Compiler.CompilerFlags

Default Luau 0.748 compiler flags, overridable per call through CompileOptions.flags.

Functions ​

compile ​

luau
Compiler.compile(sourceOrParseResult: string | PublicTypes.ParseResult, compileOpts: CompileOptions?): (string?, string?)

Compiles Luau source code or a parsed AST into a serialized bytecode string, returning (bytecode, nil) or (nil, err).

compileResult ​

luau
Compiler.compileResult(sourceOrParseResult: string | PublicTypes.ParseResult, compileOpts: CompileOptions?): CompileResult

Compiles Luau source code and returns a structured result with bytecode, diagnostics, and builder state.

compileProto ​

luau
Compiler.compileProto(sourceOrParseResult: string | PublicTypes.ParseResult, compileOpts: CompileOptions?): (PublicTypes.ProtoModule?, string?)

Compiles Luau source code or a parsed AST directly into an in-memory ProtoModule without binary serialization.