luaur-require 0.1.1

Require-by-string module resolution for Luau (Rust).
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use core::ffi::c_char;

use luaur_vm::functions::lua_setfield::lua_setfield;
use luaur_vm::macros::lua_newtable::lua_newtable;
use luaur_vm::macros::lua_registryindex::LUA_REGISTRYINDEX;

// C++ RequireImpl.cpp: `static const char* requiredCacheTableKey = "_MODULES";`
const required_cache_table_key: *const c_char = c"_MODULES".as_ptr();

pub fn clear_cache(l: *mut luaur_vm::records::lua_state::lua_State) -> i32 {
    unsafe {
        lua_newtable(l);

        lua_setfield(l, LUA_REGISTRYINDEX, required_cache_table_key);
    }
    0
}