mirror of
https://github.com/lune-org/lune.git
synced 2024-12-13 13:30:38 +00:00
Start work on improved module loader
This commit is contained in:
parent
0f5f173488
commit
1876a25922
1 changed files with 19 additions and 2 deletions
|
@ -44,7 +44,9 @@ pub fn create(lua: &'static Lua) -> LuaResult<LuaTable> {
|
|||
let require_get_abs_rel_paths = lua
|
||||
.create_function(
|
||||
|_, (require_pwd, require_source, require_path): (String, String, String)| {
|
||||
// TODO: Special case for @lune prefix here
|
||||
if require_path.starts_with('@') {
|
||||
return Ok((require_path.clone(), require_path));
|
||||
}
|
||||
let path_relative_to_pwd = PathBuf::from(
|
||||
&require_source
|
||||
.trim_start_matches("[string \"")
|
||||
|
@ -76,7 +78,22 @@ pub fn create(lua: &'static Lua) -> LuaResult<LuaTable> {
|
|||
// were async then one lua script may require a module during the file reading process
|
||||
let require_get_loaded_file = lua.create_function(
|
||||
|lua: &Lua, (path_absolute, path_relative): (String, String)| {
|
||||
// TODO: Check for @lune prefix here and try to load a builtin module
|
||||
// Check if we got a special require path starting with an @
|
||||
if path_absolute == path_relative && path_absolute.starts_with('@') {
|
||||
return match path_absolute {
|
||||
p if p.starts_with("@lune/") => {
|
||||
let _module_name = p.strip_prefix("@lune/").unwrap();
|
||||
// TODO: Return builtin module
|
||||
Err(LuaError::RuntimeError(
|
||||
"Builtin require paths prefixed by '@' are not yet supported"
|
||||
.to_string(),
|
||||
))
|
||||
}
|
||||
_ => Err(LuaError::RuntimeError(
|
||||
"Custom require paths prefixed by '@' are not yet supported".to_string(),
|
||||
)),
|
||||
};
|
||||
}
|
||||
// Use a name without extensions for loading the chunk, the
|
||||
// above code assumes the require path is without extensions
|
||||
let path_relative_no_extension = path_relative
|
||||
|
|
Loading…
Reference in a new issue