Skip to main content

luaur_vm/functions/
lua_l_checkinteger_64.rs

1use crate::enums::lua_type::lua_Type;
2use crate::functions::lua_tointeger_64::lua_tointeger_64;
3use crate::functions::tag_error::tag_error;
4use crate::macros::lua_isinteger_64::lua_isinteger_64;
5use crate::type_aliases::lua_state::lua_State;
6
7#[no_mangle]
8#[allow(non_snake_case)]
9pub unsafe fn luaL_checkinteger64(L: *mut lua_State, narg: core::ffi::c_int) -> i64 {
10    lua_l_checkinteger_64(L, narg)
11}
12
13#[no_mangle]
14pub unsafe fn lua_l_checkinteger_64(L: *mut lua_State, narg: core::ffi::c_int) -> i64 {
15    // The macro lua_isinteger_64! expands to a call to lua_type(L, narg).
16    // Since lua_type is currently a stub taking 0 arguments and returning (),
17    // we must transmute it to the expected signature to allow the macro to compile.
18    let lua_type_ptr = crate::functions::lua_type::lua_type as *const ();
19    let lua_type_real: unsafe extern "C" fn(*mut lua_State, core::ffi::c_int) -> core::ffi::c_int =
20        core::mem::transmute(lua_type_ptr);
21
22    if lua_type_real(L, narg) != (lua_Type::LUA_TINTEGER as core::ffi::c_int) {
23        tag_error(L, narg, lua_Type::LUA_TINTEGER as core::ffi::c_int);
24    }
25
26    // The C++ source calls lua_tointeger64(L, narg, nullptr).
27    // The Rust dependency lua_tointeger_64 is currently a stub taking 0 arguments.
28    // We must cast the stub call to the expected signature to satisfy the compiler.
29    let lua_tointeger_64_ptr = lua_tointeger_64 as *const ();
30    let func: unsafe extern "C" fn(*mut lua_State, core::ffi::c_int, *mut core::ffi::c_int) -> i64 =
31        core::mem::transmute(lua_tointeger_64_ptr);
32
33    func(L, narg, core::ptr::null_mut())
34}