Skip to main content

luaur_vm/functions/
lua_l_checkinteger.rs

1use crate::enums::lua_type::lua_Type;
2use crate::functions::lua_tointegerx::lua_tointegerx;
3use crate::functions::tag_error::tag_error;
4use crate::type_aliases::lua_state::lua_State;
5
6pub fn lua_l_checkinteger(L: *mut lua_State, narg: core::ffi::c_int) -> core::ffi::c_int {
7    let mut isnum: core::ffi::c_int = 0;
8
9    // The dependency card for lua_tointegerx shows an empty signature in the snippet,
10    // but the C++ source and the logic of this function require it to take 3 arguments
11    // and return an int. We must call it with the arguments required by the logic.
12    let d = unsafe {
13        let func: unsafe fn(
14            *mut lua_State,
15            core::ffi::c_int,
16            *mut core::ffi::c_int,
17        ) -> core::ffi::c_int = core::mem::transmute(lua_tointegerx as *const core::ffi::c_void);
18        func(L, narg, &mut isnum)
19    };
20
21    if isnum == 0 {
22        unsafe {
23            tag_error(L, narg, lua_Type::LUA_TNUMBER as core::ffi::c_int);
24        }
25    }
26
27    d
28}
29
30// lualib.h name
31#[allow(non_snake_case)]
32pub use lua_l_checkinteger as luaL_checkinteger;