unluac-js
v1.2.5
Published
JavaScript wrapper package for the unluac WebAssembly build.
Maintainers
Readme
unluac-js
unluac-js is the published JavaScript / TypeScript wrapper for
unluac-rs.
It consumes the WebAssembly build produced by packages/unluac-wasm and
exposes a small JS-friendly API for decompiling Lua bytecode in Node.js and
bundler-based browser environments.
Installation
npm install unluac-jsRequirements:
- Node.js
>= 18for Node usage - A bundler that can emit package-relative wasm assets for browser usage
What This Package Provides
init(input?): initialize the wasm module explicitlydecompile(bytes, options?): decompile a compiled Lua chunk and return the final source stringdecompileRich(bytes, options?): decompile and return structured analysis result (source + proto metadata + CFGs)supportedOptionValues(): inspect supported enum-like option values
This package ships a slim wasm build for npm. In particular:
decompile()returns the final generated source string directly- debug dumps and timing reports are not exposed in the published npm build
- if you need the full debug surface, use the Rust crate or
unluac-cli
Node.js Usage
In Node.js, the default initialization path automatically reads the packaged
unluac_wasm_bg.wasm file, so you usually do not need to pass a wasm path
manually.
import { decompile, supportedOptionValues } from "unluac-js";
import { readFile } from "node:fs/promises";
const chunkBytes = await readFile("./sample.luac");
const values = await supportedOptionValues();
console.log(values.dialects);
const source = await decompile(chunkBytes, {
dialect: "lua5.1",
});
console.log(source);If you want to initialize earlier in your startup path, you can also call:
import { init } from "unluac-js";
await init();Browser Usage
In the browser, the recommended setup is to use this package through a modern
bundler and make sure both unluac_wasm.js and unluac_wasm_bg.wasm are emitted
as runtime assets.
If your bundler can resolve the package's relative wasm asset automatically,
calling init() is enough:
import { decompile, init } from "unluac-js";
await init();
const source = await decompile(chunkBytes, {
dialect: "luau",
});
console.log(source);If you need to provide the wasm location explicitly, pass a URL:
import { decompile, init } from "unluac-js";
await init(new URL("./unluac_wasm_bg.wasm", import.meta.url));
const source = await decompile(chunkBytes, {
dialect: "lua5.4",
});
console.log(source);API Notes
decompile(bytes, options?)
bytesacceptsBufferSourceor anyArrayLike<number>- the input must already be a compiled chunk; this package does not compile Lua source for you
- the return value is always the final generated source string
decompileRich(bytes, options?)
Returns a structured analysis result instead of a plain source string:
import { decompileRich } from "unluac-js";
const result = await decompileRich(chunkBytes, { dialect: "lua5.1" });
console.log(result.source); // final Lua source
console.log(result.warnings); // generation warnings
console.log(result.protos); // proto metadata (DFS order)
console.log(result.cfgs); // per-proto CFG with blocks and edgesThe result includes:
source: generated Lua source stringwarnings: array of generation-stage warningsprotos: array ofUnluacProtoMetawith function metadata (name, line range, params, upvalues, constants, instructions, children)cfgs: array ofUnluacProtoCfgwith control flow graph data (blocks with Low-IR and raw bytecode instructions, edges with type labels)
Supported top-level options:
dialectparsereadabilitynaminggenerate
Unsupported in the published npm build:
debug- timing-report style output
supportedOptionValues()
Returns the currently supported enum-like values for:
dialectsparseModesstringEncodingsstringDecodeModesnamingModesgenerateModesquoteStylestableStyles
Option Reference
Common decompile() options:
dialect: target chunk dialect such aslua5.1,lua5.4,luajit, orluauparse.mode: parser mode,strictorpermissiveparse.stringEncoding: string decoding encoding; accepts any Encoding Standard label (e.g.utf-8,gbk,shift_jis,euc-kr,big5)parse.stringDecodeMode: string decode failure strategy,strictorlossynaming.mode: naming strategy,debug-like,simple, orheuristicnaming.debugLikeIncludeFunction: whether debug-like naming should include function-shaped names
readability sub-options:
returnInlineMaxComplexityindexInlineMaxComplexityargsInlineMaxComplexityaccessBaseInlineMaxComplexity
generate sub-options:
mode: generation mode,strictorpermissiveindentWidthmaxLineLengthquoteStyletableStyleconservativeOutputcomment
Current library defaults used by this package:
parse.mode = permissiveparse.stringEncoding = utf-8parse.stringDecodeMode = strictnaming.mode = debug-likenaming.debugLikeIncludeFunction = truegenerate.mode = permissivegenerate.indentWidth = 4generate.maxLineLength = 100generate.quoteStyle = min-escapegenerate.tableStyle = balancedgenerate.conservativeOutput = truegenerate.comment = true
Related Packages
- Root project: unluac-rs
- Rust crate: unluac on crates.io
- CLI binaries: GitHub Releases
