Skip to main content

luaur_vm/functions/
lua_v_tryfunc_tm.rs

1use crate::functions::lua_t_gettmbyobj::lua_t_gettmbyobj;
2use crate::macros::lua_g_typeerror::luaG_typeerror;
3use crate::macros::setobj_2_s::setobj2s;
4use crate::macros::ttisfunction::ttisfunction;
5use crate::records::lua_state::lua_State;
6use crate::type_aliases::lua_state::LuaState;
7use crate::type_aliases::stk_id::StkId;
8use crate::type_aliases::t_value::TValue;
9use luaur_common::macros::luau_noinline::LUAU_NOINLINE;
10
11#[allow(non_snake_case)]
12#[no_mangle]
13pub unsafe fn lua_v_tryfunc_tm(L: *mut LuaState, func: StkId) {
14    let tm = lua_t_gettmbyobj(
15        L as *mut lua_State,
16        func,
17        crate::type_aliases::tms::TMS::TM_CALL,
18    );
19    if !ttisfunction!(tm) {
20        luaG_typeerror!(L as *mut lua_State, func, c"call".as_ptr());
21    }
22
23    let mut p = (*L).top;
24    while p > func {
25        setobj2s!(L as *mut lua_State, p, p.wrapping_sub(1));
26        p = p.wrapping_sub(1);
27    }
28
29    (*L).top = (*L).top.wrapping_add(1);
30    setobj2s!(L as *mut lua_State, func, tm);
31}