Disassembler

disassemble

Disassembles a Luau function and returns a formatted bytecode listing string.

Syntax

disassemble(callback: function, options?: DisassembleOptions): string

Arguments

NameTypeDescription
callbackfunctionLuau function to disassemble. C closures are rejected.
options?DisassembleOptionsOptional table read for Recursive, ShowLines, ShowConstants, and StringPreviewMax. Missing fields or fields with the wrong type leave the default value unchanged.

Returns

NameTypeDescription
assemblystringFormatted disassembly text with a trailing newline.

Description

Disassembles a Luau function and returns a formatted bytecode listing string. Argument 1 must be a function; otherwise a type error reports expected function. The closure must be valid and must not be a C closure; invalid closures raise "invalid closure" and C closures raise "cannot disassemble C closure". When an optional second argument is present, the function reads Recursive, ShowLines, ShowConstants, and StringPreviewMax from it. Boolean option fields override the matching defaults, and a numeric StringPreviewMax overrides the default string preview length. Indata structureions are decoded with the bytecode decoder before formatting. The output always has one trailing newline and the function has no registered alias.

Call it with 2 parameter(s): callback, options. The argument table explains which values are required and which ones only refine the behavior.

It returns assembly (string). Use the returns table to separate successful values from nil results and recoverable errors.

Example

Disassemble a callback with selected output options.

local assembly = disassemble(function(value)
    return value * 2
end, {
    Recursive = false,
    ShowLines = true,
    ShowConstants = true,
})

print(assembly)

Types

DisassembleOptions

Controls how Luau bytecode is rendered in the disassembly output.

Recursive? boolean Includes nested child prototypes in the output.ShowLines? boolean Shows source line numbers next to instructions when line data is available.ShowConstants? boolean Lists the constant table for each prototype.StringPreviewMax? integer Limits the number of characters shown when previewing string constants.