Skip to main content

luaur_vm/functions/
lua_c_enumheap.rs

1use crate::functions::enumgco::enumgco;
2use crate::functions::lua_m_visitgco::lua_m_visitgco;
3use crate::records::enum_context::EnumContext;
4use crate::records::gc_object::GCObject;
5use crate::type_aliases::lua_state::lua_State;
6use core::ffi::{c_char, c_void};
7
8#[allow(non_snake_case)]
9pub unsafe fn lua_c_enumheap(
10    l: *mut lua_State,
11    context: *mut c_void,
12    node: Option<unsafe extern "C" fn(*mut c_void, *mut c_void, u8, u8, usize, *const c_char)>,
13    edge: Option<unsafe extern "C" fn(*mut c_void, *mut c_void, *mut c_void, *const c_char)>,
14) {
15    let g = (*l).global;
16
17    let mut ctx = EnumContext {
18        L: l,
19        context,
20        node,
21        edge,
22    };
23
24    // In Luau, lua_State is a collectible object. Its first field is hdr (GCheader),
25    // which contains the tt, marked, and memcat fields required by GCObject.
26    // The obj2gco macro expects a pointer to something that has these fields.
27    // We cast the mainthread (lua_State*) to GCObject* to satisfy the macro and the enumgco signature.
28    let mainthread_gco = (*g).mainthread as *mut GCObject;
29
30    enumgco(
31        &mut ctx as *mut EnumContext as *mut c_void,
32        core::ptr::null_mut(),
33        mainthread_gco,
34    );
35
36    lua_m_visitgco(
37        l,
38        &mut ctx as *mut EnumContext as *mut c_void,
39        enumgco as *mut c_void,
40    );
41}
42
43#[allow(non_snake_case)]
44pub unsafe fn luaC_enumheap(
45    L: *mut lua_State,
46    context: *mut c_void,
47    node: Option<unsafe extern "C" fn(*mut c_void, *mut c_void, u8, u8, usize, *const c_char)>,
48    edge: Option<unsafe extern "C" fn(*mut c_void, *mut c_void, *mut c_void, *const c_char)>,
49) {
50    lua_c_enumheap(L, context, node, edge);
51}