Skip to main content

luaur_vm/functions/
lua_g_onbreak.rs

1//! `luaG_onbreak` — returns true when the current instruction at the top
2//! call frame is `LOP_BREAK`.
3//! C++ source: `VM/src/ldebug.cpp:405`
4
5use crate::enums::lua_type::lua_Type;
6use crate::records::lua_state::lua_State;
7use luaur_common::enums::luau_opcode::LuauOpcode;
8use luaur_common::macros::luau_insn_op::LUAU_INSN_OP;
9
10#[no_mangle]
11#[allow(non_snake_case)]
12pub unsafe fn luaG_onbreak(l: *mut lua_State) -> bool {
13    if (*l).ci == (*l).base_ci {
14        return false;
15    }
16
17    // isLua(ci): ci->func is a function && !clvalue(ci->func)->isC
18    // Inline to avoid the broken ttisfunction! macro.
19    let func = (*(*l).ci).func;
20    if (*func).tt() != lua_Type::LUA_TFUNCTION as core::ffi::c_int {
21        return false;
22    }
23    if (*(*(*func).value.gc).cl).isC != 0 {
24        return false;
25    }
26
27    LUAU_INSN_OP(*(*(*l).ci).savedpc) == LuauOpcode::LOP_BREAK as u32
28}