1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! # luadec-rust
//!
//! A Lua 5.1 bytecode decompiler library.
//!
//! This crate takes compiled Lua 5.1 bytecode and produces readable Lua source code.
//!
//! ## Quick Start
//!
//! ```no_run
//! let bytecode = std::fs::read("input.luac").unwrap();
//! let source = luadec_rust::decompile(&bytecode).unwrap();
//! println!("{}", source);
//! ```
//!
//! ## Advanced Usage
//!
//! For more control, use the [`lua51`] module directly:
//!
//! ```no_run
//! use luac_parser::lua_bytecode;
//! use luadec_rust::lua51::lifter::Lifter;
//! use luadec_rust::lua51::emit;
//!
//! let data = std::fs::read("input.luac").unwrap();
//! let (_, bytecode) = lua_bytecode(&data).unwrap();
//! let func = Lifter::decompile(&bytecode.main_chunk);
//! let source = emit::emit_chunk(&func);
//! ```
/// Decompile Lua 5.1 bytecode into Lua source code.
///
/// Takes raw bytecode bytes (e.g. from a `.luac` file) and returns
/// the decompiled Lua source as a `String`.
///
/// # Errors
///
/// Returns an error string if the bytecode cannot be parsed.
///
/// # Example
///
/// ```no_run
/// let bytecode = std::fs::read("compiled.luac").unwrap();
/// let source = luadec_rust::decompile(&bytecode).unwrap();
/// println!("{}", source);
/// ```