Skip to main content

luaur_vm/functions/
lua_d_check_cstack.rs

1use crate::enums::lua_status::lua_Status;
2use crate::functions::lua_d_throw_ldo::lua_d_throw;
3use crate::macros::luai_maxccalls::LUAI_MAXCCALLS;
4use crate::type_aliases::lua_state::lua_State;
5
6#[no_mangle]
7#[allow(non_snake_case)]
8pub unsafe fn luaD_checkCstack(L: *mut lua_State) {
9    // allow extra stack space to handle stack overflow in xpcall
10    let hardlimit: i32 = LUAI_MAXCCALLS + (LUAI_MAXCCALLS >> 3);
11
12    if (*L).nCcalls as i32 == LUAI_MAXCCALLS {
13        crate::functions::lua_g_runerror_l::lua_g_runerror_l(
14            L,
15            core::ptr::null(),
16            format_args!("C stack overflow"),
17        );
18    } else if (*L).nCcalls as i32 >= hardlimit {
19        lua_d_throw(L, lua_Status::LUA_ERRERR as i32);
20    }
21}
22
23#[allow(non_snake_case)]
24pub use luaD_checkCstack as lua_d_check_cstack;