Skip to main content

luaur_vm/functions/
int_64_fromstring.rs

1use crate::functions::lua_l_optinteger::lua_l_optinteger;
2use crate::functions::lua_o_str_2_l::lua_o_str_2_l;
3use crate::functions::lua_pushinteger_64::lua_pushinteger_64;
4use crate::functions::lua_pushnil::lua_pushnil;
5use crate::macros::lua_l_argcheck::luaL_argcheck;
6use crate::macros::lua_l_checkstring::luaL_checkstring;
7use crate::type_aliases::lua_state::lua_State;
8
9#[no_mangle]
10pub unsafe fn int64_fromstring(L: *mut lua_State) -> core::ffi::c_int {
11    let s = luaL_checkstring!(L, 1);
12    let base = lua_l_optinteger(L, 2, 10);
13    luaL_argcheck!(
14        L,
15        (2 <= base as i32) && (base as i32 <= 36),
16        2,
17        "base out of range"
18    );
19
20    let mut result: i64 = 0;
21    if lua_o_str_2_l(s, &mut result, base as i32) != 0 {
22        lua_pushinteger_64(L, result);
23    } else {
24        lua_pushnil(L);
25    }
26
27    1
28}