Skip to main content

luaur_vm/functions/
lua_h_new.rs

1use crate::enums::lua_type::lua_Type;
2use crate::functions::setarrayvector::setarrayvector;
3use crate::functions::setnodevector::setnodevector;
4use crate::macros::dummynode::dummynode;
5use crate::macros::lua_c_init::luaC_init;
6use crate::records::gc_object::GCObject;
7use crate::records::lua_node::LuaNode;
8use crate::records::lua_table::LuaTable;
9use crate::type_aliases::lua_state::lua_State;
10use core::ffi::c_int;
11
12#[allow(non_snake_case)]
13pub unsafe fn lua_h_new(l: *mut lua_State, narray: c_int, nhash: c_int) -> *mut LuaTable {
14    let t = crate::functions::lua_m_newgco::luaM_newgco_(
15        l,
16        core::mem::size_of::<LuaTable>(),
17        (*l).activememcat,
18    ) as *mut LuaTable;
19
20    luaC_init!(l, t, lua_Type::LUA_TTABLE as c_int);
21    (*t).metatable = core::ptr::null_mut();
22    (*t).tmcache = !0u8;
23    (*t).array = core::ptr::null_mut();
24    (*t).sizearray = 0;
25    (*t).union.lastfree = 0;
26    (*t).lsizenode = 0;
27    (*t).readonly = 0;
28    (*t).safeenv = 0;
29    (*t).nodemask8 = 0;
30    (*t).node = dummynode as *mut LuaNode;
31
32    if narray > 0 {
33        setarrayvector(l, t, narray);
34    }
35
36    if nhash > 0 {
37        setnodevector(l, t, nhash);
38    }
39
40    t
41}
42
43#[export_name = "luaH_new"]
44pub unsafe extern "C" fn lua_h_new_export(
45    l: *mut lua_State,
46    narray: c_int,
47    nhash: c_int,
48) -> *mut core::ffi::c_void {
49    lua_h_new(l, narray, nhash).cast()
50}
51
52#[allow(unused_imports)]
53pub use lua_h_new as luaH_new;