Skip to main content

lua_types/
proto.rs

1//! `LuaProto` — compiled function prototype. Mirrors C-Lua's `Proto` struct
2//! but uses Rust idioms (Vec instead of pointer+size pairs).
3
4use crate::gc::GcRef;
5use crate::opcode::Instruction;
6use crate::string::LuaString;
7use crate::value::LuaValue;
8
9#[derive(Debug)]
10pub struct LuaProto {
11    pub numparams: u8,
12    pub is_vararg: bool,
13    pub maxstacksize: u8,
14    pub upvalues: Vec<UpvalDesc>,
15    pub k: Vec<LuaValue>,
16    pub code: Vec<Instruction>,
17    pub p: Vec<GcRef<LuaProto>>,
18    pub lineinfo: Vec<i8>,
19    pub abslineinfo: Vec<AbsLineInfo>,
20    pub locvars: Vec<LocalVar>,
21    pub linedefined: i32,
22    pub lastlinedefined: i32,
23    pub source: Option<GcRef<LuaString>>,
24}
25
26impl LuaProto {
27    pub fn placeholder() -> Self {
28        LuaProto {
29            numparams: 0,
30            is_vararg: false,
31            maxstacksize: 2,
32            upvalues: Vec::new(),
33            k: Vec::new(),
34            code: Vec::new(),
35            p: Vec::new(),
36            lineinfo: Vec::new(),
37            abslineinfo: Vec::new(),
38            locvars: Vec::new(),
39            linedefined: 0,
40            lastlinedefined: 0,
41            source: None,
42        }
43    }
44}
45
46#[derive(Debug, Clone)]
47pub struct UpvalDesc {
48    pub name: Option<GcRef<LuaString>>,
49    pub instack: bool,
50    pub idx: u8,
51    pub kind: u8,
52}
53
54#[derive(Debug, Clone)]
55pub struct LocalVar {
56    pub varname: GcRef<LuaString>,
57    pub startpc: i32,
58    pub endpc: i32,
59}
60
61#[derive(Debug, Clone, Copy)]
62pub struct AbsLineInfo {
63    pub pc: i32,
64    pub line: i32,
65}
66
67// ──────────────────────────────────────────────────────────────────────────────
68// PORT STATUS
69//   source:        src/lobject.h (Proto struct)
70//   target_crate:  lua-types
71//   confidence:    high
72//   todos:         0
73//   port_notes:    0
74//   unsafe_blocks: 0
75//   notes:         Function prototype: bytecode, constants, line info, debug info,
76//                  upvalue descriptors. Faithful layout of C's Proto struct using
77//                  Vec<T> in place of T*+size pairs.
78// ──────────────────────────────────────────────────────────────────────────────