Opcode reference

The Lua compiler in this library lowers source to a flat stream of register-based opcodes. There are no labels and no PC-relative jumps — control flow is threaded through an explicit continuation list inside the executor. The full set of opcodes the disassembler emits is documented below.

Loads & moves

Get values into registers — constants, nil, booleans, and register-to-register copies.

load_constant rD, K

Load a literal value (number, string, nil, bool) into a register.

load_nil rD, N

Set N consecutive registers to nil.

load_boolean rD, bool

Load a boolean literal into a register.

load_env rD

Load the global environment table (`_ENV`) into a register.

move rD, rS

Copy one register to another.

Globals & upvalues

Read and write the global environment and captured outer-scope bindings.

get_global rD, name

Read a global variable by name.

set_global name, rS

Write a global variable by name.

get_upvalue rD, up[i]

Read a captured outer-scope binding (upvalue).

set_upvalue up[i], rS

Write a captured outer-scope binding (upvalue).

get_open_upvalue rD, rS

Read a still-on-the-stack upvalue (set before the parent function returned).

set_open_upvalue rD, rS

Write an open upvalue while the parent is still live.

Tables

Allocate, index, field-access, and bulk-fill the universal Lua data structure.

new_table rD, array, hash

Allocate a new table with the given array/hash pre-sizing.

get_table rD, rT, k

Read t[k] into a register.

set_table rT, k, rV

Write t[k] from a register.

get_field rD, rT, name

Read t.name (string-keyed field) — faster path than get_table.

set_field rT, name, rV

Write t.name from a register.

set_list rT, start, count, off

Bulk-write a slice of registers into the array part of a table.

self rD, rO, name

Method-call shim: load t and t.name into adjacent registers for `obj:method(...)`.

Arithmetic & strings

Numeric and bitwise ops, plus string concatenation and length.

add rD, rA, rB

Numeric addition.

subtract rD, rA, rB

Numeric subtraction.

multiply rD, rA, rB

Numeric multiplication.

divide rD, rA, rB

Float division (`/`).

floor_divide rD, rA, rB

Integer floor division (`//`).

modulo rD, rA, rB

Modulo (`%`).

power rD, rA, rB

Exponentiation (`^`).

negate rD, rS

Numeric negation.

concatenate rD, rA, rB

String concatenation (`..`).

length rD, rS

`#x` — string length, array length, or `__len` metamethod.

bitwise_and rD, rA, rB

Bitwise AND (`&`).

bitwise_or rD, rA, rB

Bitwise OR (`|`).

bitwise_xor rD, rA, rB

Bitwise XOR (`~` binary).

bitwise_not rD, rS

Bitwise NOT (`~` unary).

shift_left rD, rA, rB

Bit shift left (`<<`).

shift_right rD, rA, rB

Bit shift right (`>>`).

Comparison & logic

Equality, ordering, and short-circuit logical control.

equal rD, rA, rB

Equality comparison (`==`).

less_than rD, rA, rB

Less-than comparison (`<`).

less_equal rD, rA, rB

Less-or-equal comparison (`<=`).

not rD, rS

Logical not.

test rR

If register is truthy, run the next continuation; else fall through.

test_true rR

If register is truthy, fall through; else skip.

test_and rD, rS

Short-circuit AND: if src is falsy, copy to dest and skip; else continue.

test_or rD, rS

Short-circuit OR: if src is truthy, copy to dest and skip; else continue.

Control flow

Loops and structured exits. Most jumps live on the continuation list, not as PC offsets.

while_loop

While-loop control: test, body, jump back.

repeat_loop

Repeat-until control: body, test, jump back.

numeric_for rB

Numeric for-loop: increments the loop variable and continues until done.

generic_for rB, vars

Generic for-loop over an iterator (`pairs`, `ipairs`, custom).

break

Jump out of the nearest enclosing loop.

scope registers

Allocate a new register-window for the enclosing block.

Calls & returns

Invoke and return — including tail calls, varargs, and the method-shim for `obj:method(...)`.

call rB, argc, resc

Call a function. Args/results encoded as fixed counts, multi, or varargs.

tail_call rB, argc

Tail-position call — replaces the current frame instead of pushing.

return rB, count

Return zero or more values from the current function.

return_vararg (varargs)

Return whatever varargs the current function received.

vararg rB, count

Materialise `...` into consecutive registers.

Closures

Build nested functions with captured upvalues.

closure rD, proto[i]

Build a closure from a nested prototype, capturing its upvalues.

Metadata

Pseudo-instructions for source tracking and debugging.

source_line line

Source-line marker (used for error traces and stepping).