Skip to main content

luaur_bytecode/methods/
bc_function_as.rs

1use crate::records::bc_function::BcFunction;
2use crate::records::bc_inst::BcInst;
3use crate::records::bc_op::BcOp;
4use crate::records::bc_ref::BcRef;
5use luaur_common::macros::luau_assert::LUAU_ASSERT;
6
7pub trait BcInstType {
8    const OPCODE: i32;
9}
10
11impl BcFunction {
12    pub fn as_<T>(&self, op: BcOp) -> T
13    where
14        T: BcInstType + for<'a> From<(&'a BcFunction, BcRef<'a, BcInst>)>,
15    {
16        let insn = self.inst(op);
17        LUAU_ASSERT!(insn.operator_deref().op as i32 == T::OPCODE);
18
19        T::from((self, insn))
20    }
21}