| Crates.io | luadec |
| lib.rs | luadec |
| version | 0.2.0 |
| created_at | 2025-06-05 02:02:23.71037+00 |
| updated_at | 2025-06-05 02:02:23.71037+00 |
| description | A Lua 5.1 bytecode decompiler library, originated from lbcdec |
| homepage | |
| repository | https://github.com/ItsLucas/luadec |
| max_upload_size | |
| id | 1701014 |
| size | 515,635 |
A Lua 5.1 bytecode decompiler library written in Rust, originated from the lbcdec project.
Add this to your Cargo.toml:
[dependencies]
luadec = "0.2.0"
use luadec::LuaDecompiler;
// Read bytecode from file
let bytecode = std::fs::read("script.luac")?;
// Create decompiler and decompile
let decompiler = LuaDecompiler::new();
let source_code = decompiler.decompile(&bytecode)?;
println!("{}", source_code);
use luadec::{LuaDecompiler, DecompileOptions};
let options = DecompileOptions {
include_debug_comments: true,
indent_width: 4,
include_prototype_numbers: true,
};
let decompiler = LuaDecompiler::with_options(options);
let result = decompiler.decompile(&bytecode)?;
use luadec::batch::{BatchOptions, DecompileOptions};
let batch_options = BatchOptions {
parallel: true,
output_extension: "lua".to_string(),
decompile_options: DecompileOptions::default(),
};
// Decompile all .luac files in a directory
let results = luadec::batch::decompile_bytecode_files(
"*.luac",
Some("output/"),
batch_options,
)?;
use luadec::LuaDecompiler;
let decompiler = LuaDecompiler::new();
// Decompile file to file
decompiler.decompile_file_to_file("input.luac", "output.lua")?;
// Decompile file to string
let source = decompiler.decompile_file("input.luac")?;
pub struct DecompileOptions {
/// Include debug comments in output
pub include_debug_comments: bool,
/// Number of spaces for indentation
pub indent_width: usize,
/// Include prototype numbers in function definitions
pub include_prototype_numbers: bool,
}
pub struct BatchOptions {
/// Enable parallel processing
pub parallel: bool,
/// Output file extension
pub output_extension: String,
/// Decompilation options
pub decompile_options: DecompileOptions,
}
The library provides detailed error information:
use luadec::{DecompileError, DecompileResult};
match decompiler.decompile(&bytecode) {
Ok(source) => println!("Success: {}", source),
Err(DecompileError::InvalidBytecode(msg)) => {
eprintln!("Invalid bytecode: {}", msg);
},
Err(DecompileError::DecompileError(msg)) => {
eprintln!("Decompilation failed: {}", msg);
},
Err(DecompileError::IoError(err)) => {
eprintln!("IO error: {}", err);
},
}
git clone https://github.com/ItsLucas/luadec.git
cd luadec
cargo build --release
cargo test
cargo doc --open
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
lbcdec project by Dwayne Slater