decompile
Decompiles Luau bytecode into source text.
Syntax
decompile(source: LuaSourceContainer | string, options: DecompilerOptions?) -> string
DecompilerOptions.new() -> DecompilerOptions
DecompilerFormatter.new() -> DecompilerFormatterParameters
| Parameter | Type | Description |
|---|---|---|
source | LuaSourceContainer | string | A client-visible script or raw Luau bytecode |
options | DecompilerOptions? | Optional decompiler settings |
Description
Pass a script to decompile it directly, or pass a Luau bytecode string. Server-running Script instances are not supported.
The function yields until decompilation finishes and raises an error if the input cannot be decompiled.
DecompilerOptions
DecompilerOptions.new() initializes its fields from Volt's current decompiler settings.
| Property | Type | Description |
|---|---|---|
SmartVariableRenamer | boolean | Improve generated local-variable names |
FunctionDeclarations | boolean | Recover declaration-style functions when possible |
GuardClauses | boolean | Recover guard-clause control flow |
ConstantFolding | boolean | Fold eligible constant expressions |
ConditionalStructurer | boolean | Reconstruct conditional control flow |
DoBlockInsertionThreshold | number | Threshold used when inserting do blocks |
Formatter | DecompilerFormatter | Formatter configuration |
DecompilerFormatter
DecompilerFormatter.new() also uses the current Volt settings as its defaults.
| Property | Type | Description |
|---|---|---|
IndentWidth | number | Spaces used for each indentation level |
ColumnLimit | number | Preferred output column limit |
ParenthesizeConditions | boolean | Add parentheses around conditions |
AppendSemicolons | boolean | Append semicolons to statements |
FunctionMetadataEnabled | boolean | Emit function metadata |
FunctionMetadataLayout | number | Metadata layout constant |
FunctionMetadataIncludeName | boolean | Include function names in metadata |
FunctionMetadataIncludeLine | boolean | Include source lines in metadata |
FunctionMetadataIncludeUpvalues | boolean | Include upvalue information |
FunctionMetadataUpvalueFormat | number | Upvalue-format constant |
Metadata Constants
DecompilerFormatter.FunctionMetadata.Layout.Block
DecompilerFormatter.FunctionMetadata.Layout.Inline
DecompilerFormatter.FunctionMetadata.UpvalueFormat.Name
DecompilerFormatter.FunctionMetadata.UpvalueFormat.Kind
DecompilerFormatter.FunctionMetadata.UpvalueFormat.KindAndIndexExample
local module = getloadedmodules()[1]
assert(module, "No loaded ModuleScript was available")
local options = DecompilerOptions.new()
options.SmartVariableRenamer = true
options.GuardClauses = true
options.Formatter.IndentWidth = 4
options.Formatter.ColumnLimit = 100
options.Formatter.FunctionMetadataEnabled = true
options.Formatter.FunctionMetadataLayout =
DecompilerFormatter.FunctionMetadata.Layout.Block
local success, sourceOrError = pcall(decompile, module, options)
if success then
print(sourceOrError)
else
warn("Decompilation failed:", sourceOrError)
endRaw Bytecode
local module = assert(getloadedmodules()[1])
local bytecode = getscriptbytecode(module)
local source = decompile(bytecode)
print(source)Related Functions
getscriptbytecode- Retrieve script bytecodegetscripthash- Hash script bytecode
Related Guides
- Decompiler - Pipeline overview