Skip to content

VM ​

Pure-Luau Luau 0.748 register VM with isolated environments, execution budgets, and debug hooks.

Types ​

Proto type ​

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

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

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.

BytecodeDecoder type ​

luau
type BytecodeDecoder = ((number) -> number) | { decode: (self: any, code: { number }) -> () }

LoadMode type ​

luau
type LoadMode = "text" | "binary" | "auto"

LoadOptions type ​

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

EnvironmentOptions type ​

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

ResourceLimits type ​

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

DebugFrameInfo type ​

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

luau
type CoverageEntry = {
	name: string?,
	lineDefined: number,
	hits: { [number]: number },
	totalHits: number,
}

Per-function line execution counts returned by Ouro.VM.getCoverage.

UpvalueInfo type ​

luau
type UpvalueInfo = {
	index: number,
	name: string?,
	value: any,
}

Captured upvalue metadata returned by Ouro.VM.getUpvalues.

Properties ​

createEnvironment Re-export ​

luau
VM.createEnvironment

Builds an isolated VM global environment table with pure Luau standard libraries or optional host fallbacks.

sandbox Re-export ​

luau
VM.sandbox

Creates a writable per-chunk overlay table backed read-only by baseEnv with isolated RNG state.

traceback Re-export ​

luau
VM.traceback

Formats a guest VM stack trace matching upstream luaL_traceback.

getCoverage Re-export ​

luau
VM.getCoverage

Returns per-proto line execution counts for closures compiled with coverageLevel 1 or 2.

cloneFunction Re-export ​

luau
VM.cloneFunction

Clones a VM closure sharing upvalue references with optional new environment and load overrides.

getUpvalues Re-export ​

luau
VM.getUpvalues

Inspects captured upvalues (1-based) on a VM closure.

setUpvalue Re-export ​

luau
VM.setUpvalue

Mutates an open or closed upvalue slot (1-based) on a VM closure.

resetBudget Re-export ​

luau
VM.resetBudget

Resets the instruction counter and clears the lazy timeout timer for the module context owning fn.

Functions ​

load ​

luau
VM.load(chunk: string | buffer | ProtoModule, options: LoadOptions?): (((...any) -> ...any)?, string?)

Compiles or deserializes a Luau chunk (source, binary bytecode, or ProtoModule) into a callable sandboxed closure.

loadBytecode ​

luau
VM.loadBytecode(bytecode: string | buffer, options: LoadOptions?): (((...any) -> ...any)?, string?)

Deserializes binary Luau bytecode (string or buffer) and loads it into a callable closure without invoking the compiler.

loadProto ​

luau
VM.loadProto(protoModule: ProtoModule, options: LoadOptions?): (((...any) -> ...any)?, string?)

Validates and instantiates a callable closure from an in-memory ProtoModule.