Skip to main content

luaur_bytecode/methods/
bytecode_builder_add_class_shape.rs

1use crate::enums::r#type::Type;
2use crate::records::bytecode_builder::BytecodeBuilder;
3use crate::records::class_shape::ClassShape;
4use crate::records::constant::Constant;
5
6impl BytecodeBuilder {
7    pub fn add_class_shape(&mut self, shape: ClassShape) -> i32 {
8        let id = self.constants.len() as u32;
9
10        const K_MAX_CONSTANT_COUNT: u32 = 0x007f_ffff;
11        if id >= K_MAX_CONSTANT_COUNT {
12            return -1;
13        }
14
15        let mut c = Constant {
16            r#type: Type::Type_ClassShape,
17            value: unsafe { core::mem::zeroed() },
18        };
19
20        unsafe {
21            c.value.valueClassShape = self.class_shapes.len() as u32;
22        }
23
24        self.class_shapes.push(shape);
25        self.constants.push(c);
26
27        id as i32
28    }
29}