diff options
author | Alex Orlenko <zxteam@protonmail.com> | 2022-06-29 00:53:07 +0100 |
---|---|---|
committer | Alex Orlenko <zxteam@protonmail.com> | 2022-06-29 11:25:16 +0100 |
commit | 70e16b51aeea2b0b2552ec7b77bfa7e6cc7c0896 (patch) | |
tree | 1c3b84fe7312ee4d7a43e88bcd4a69fa2145f2b3 /src/luau.rs | |
parent | 9596b97faabafe2876467048ec9bb82c1c1ad6e5 (diff) | |
download | mlua-70e16b51aeea2b0b2552ec7b77bfa7e6cc7c0896.zip |
Set source name to full file path in Luau require
Diffstat (limited to 'src/luau.rs')
-rw-r--r-- | src/luau.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/luau.rs b/src/luau.rs index b9b2adf..768c8cf 100644 --- a/src/luau.rs +++ b/src/luau.rs @@ -85,10 +85,12 @@ fn lua_require(lua: &Lua, name: Option<std::string::String>) -> Result<Value> { search_path = "?.luau;?.lua".into(); } - let mut source = None; + let (mut source, mut source_name) = (None, String::new()); for path in search_path.split(';') { - if let Ok(buf) = std::fs::read(path.replacen('?', &name, 1)) { + let file_path = path.replacen('?', &name, 1); + if let Ok(buf) = std::fs::read(&file_path) { source = Some(buf); + source_name = file_path; break; } } @@ -96,7 +98,7 @@ fn lua_require(lua: &Lua, name: Option<std::string::String>) -> Result<Value> { let value = lua .load(&source) - .set_name(&format!("={}", name))? + .set_name(&format!("={}", source_name))? .set_mode(ChunkMode::Text) .call::<_, Value>(())?; |