Skip to main content

luaur_vm/functions/
lua_equal.rs

1use crate::functions::index_2_addr::index2addr;
2use crate::macros::equalobj::equalobj;
3use crate::macros::lua_o_nilobject::luaO_nilobject;
4use crate::type_aliases::lua_state::lua_State;
5use crate::type_aliases::stk_id::StkId;
6use crate::type_aliases::t_value::TValue;
7
8#[no_mangle]
9#[allow(non_snake_case)]
10pub unsafe fn lua_equal(
11    L: *mut lua_State,
12    index1: core::ffi::c_int,
13    index2: core::ffi::c_int,
14) -> core::ffi::c_int {
15    let o1: StkId = index2addr(L, index1);
16    let o2: StkId = index2addr(L, index2);
17
18    let nil_ptr = luaO_nilobject as *const TValue;
19
20    let i = if (o1 as *const TValue) == nil_ptr || (o2 as *const TValue) == nil_ptr {
21        0
22    } else {
23        if equalobj!(L, o1 as *const TValue, o2 as *const TValue) {
24            1
25        } else {
26            0
27        }
28    };
29
30    i as core::ffi::c_int
31}