Skip to main content

luaur_vm/methods/
resolve_import_run.rs

1use crate::functions::lua_v_getimport::lua_v_getimport;
2use crate::macros::lua_d_checkstack::luaD_checkstack;
3use crate::macros::setnilvalue::setnilvalue;
4use crate::records::resolve_import::ResolveImport;
5use crate::type_aliases::lua_state::lua_State;
6
7impl ResolveImport {
8    pub unsafe fn run(L: *mut lua_State, ud: *mut core::ffi::c_void) {
9        let self_ = ud as *mut ResolveImport;
10
11        // note: we call getimport with nil propagation which means that accesses to table chains like A.B.C will resolve in nil
12        // this is technically not necessary but it reduces the number of exceptions when loading scripts that rely on getfenv/setfenv for global
13        // injection
14        // allocate a stack slot so that we can do table lookups
15        luaD_checkstack!(L, 1);
16        setnilvalue!((*L).top);
17        (*L).top = (*L).top.add(1);
18
19        lua_v_getimport(
20            L,
21            (*L).gt,
22            (*self_).k,
23            (*L).top.sub(1),
24            (*self_).id,
25            true, /* propagatenil= */
26        );
27    }
28}