Skip to main content

luaur_vm/functions/
lua_tounsignedx.rs

1use core::ffi::c_int;
2
3use crate::functions::index_2_addr::index2addr;
4use crate::macros::luai_num_2_unsigned::luai_num2unsigned;
5use crate::macros::nvalue::nvalue;
6use crate::macros::tonumber::tonumber;
7use crate::type_aliases::lua_state::lua_State;
8use crate::type_aliases::t_value::TValue;
9
10#[allow(non_snake_case)]
11pub unsafe fn lua_tounsignedx(L: *mut lua_State, idx: c_int, isnum: *mut c_int) -> u32 {
12    let mut n: TValue = core::mem::zeroed();
13    // The tonumber! macro may reassign the pointer if it needs to point to the converted temporary.
14    let mut o = index2addr(L, idx);
15
16    if tonumber!(o, &mut n) {
17        let mut res: u32 = 0;
18        let num = nvalue!(o);
19        luai_num2unsigned(&mut res, num);
20
21        if !isnum.is_null() {
22            *isnum = 1;
23        }
24        res
25    } else {
26        if !isnum.is_null() {
27            *isnum = 0;
28        }
29        0
30    }
31}