Skip to main content

luaur_code_gen/functions/
get_code_gen_context.rs

1use crate::records::base_code_gen_context::BaseCodeGenContext;
2use crate::type_aliases::lua_state::lua_State;
3
4#[inline]
5pub fn get_code_gen_context(L: *mut lua_State) -> *mut BaseCodeGenContext {
6    // SAFETY: This mirrors the C++ implementation:
7    // return static_cast<BaseCodeGenContext*>(L->global->ecb.context);
8    // Caller must ensure `L` is a valid lua_State pointer with a valid `global`
9    // and that `global->ecb.context` points to a BaseCodeGenContext (or is null).
10    unsafe {
11        if L.is_null() {
12            return core::ptr::null_mut();
13        }
14
15        let global = (*L).global;
16        if global.is_null() {
17            return core::ptr::null_mut();
18        }
19
20        let ctx = (*global).ecb.context;
21        ctx as *mut BaseCodeGenContext
22    }
23}