Skip to main content

luaur_bytecode/methods/
bc_function_get_inst_index.rs

1use crate::records::bc_function::BcFunction;
2use crate::records::bc_inst::BcInst;
3use luaur_common::macros::luau_assert::LUAU_ASSERT;
4
5impl BcFunction {
6    pub fn get_inst_index(&self, inst: &BcInst) -> u32 {
7        let inst_ptr = inst as *const BcInst;
8        let start_ptr = self.instructions.as_ptr();
9        let end_ptr = unsafe { start_ptr.add(self.instructions.len()) };
10
11        LUAU_ASSERT!(inst_ptr >= start_ptr && inst_ptr <= end_ptr);
12
13        let offset = unsafe { inst_ptr.offset_from(start_ptr) };
14        offset as u32
15    }
16}