luaur-bytecode 0.1.2

Luau bytecode format and builder (Rust).
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use crate::records::bc_function::BcFunction;
use crate::records::bc_inst::BcInst;
use luaur_common::macros::luau_assert::LUAU_ASSERT;

impl BcFunction {
    pub fn get_inst_index(&self, inst: &BcInst) -> u32 {
        let inst_ptr = inst as *const BcInst;
        let start_ptr = self.instructions.as_ptr();
        let end_ptr = unsafe { start_ptr.add(self.instructions.len()) };

        LUAU_ASSERT!(inst_ptr >= start_ptr && inst_ptr <= end_ptr);

        let offset = unsafe { inst_ptr.offset_from(start_ptr) };
        offset as u32
    }
}