mirror of
https://github.com/mlua-rs/mlua
synced 2026-06-08 16:05:43 +00:00
(Luau Require) Resolve Lua file path relative to the current directory
and unrelated to Rust source file location. When a Lua file is required inside a Rust file (in a chunk), we should resolve the Lua file relative to the current directory, instead of relative to the Rust chunk path. The Rust file location is an internal information that does not exist when the compiled binary runs. Fixes #605
This commit is contained in:
+4
-2
@@ -200,9 +200,11 @@ impl Require for TextRequirer {
|
||||
let chunk_path = Self::normalize_path(chunk_name.as_ref());
|
||||
|
||||
if chunk_path.extension() == Some("rs".as_ref()) {
|
||||
// Special case for Rust source files, reset to the current directory
|
||||
let chunk_filename = chunk_path.file_name().unwrap();
|
||||
let cwd = env::current_dir().map_err(|_| NavigateError::NotFound)?;
|
||||
self.abs_path = Self::normalize_path(&cwd.join(&chunk_path));
|
||||
self.rel_path = chunk_path;
|
||||
self.abs_path = Self::normalize_path(&cwd.join(chunk_filename));
|
||||
self.rel_path = ([Component::CurDir, Component::Normal(chunk_filename)].into_iter()).collect();
|
||||
self.module_path = PathBuf::new();
|
||||
|
||||
return Ok(());
|
||||
|
||||
Reference in New Issue
Block a user