Skip to content

Commit 3b382ce

Browse files
committed
fix: keep the source alias in the embedded requirer
1 parent e28e583 commit 3b382ce

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

crates/rootbeer-core/src/lua/require.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,17 @@ pub fn embedded_modules() -> &'static [(&'static str, &'static str)] {
116116
#[cfg(all(feature = "embedded-stdlib", not(debug_assertions)))]
117117
pub(crate) struct EmbeddedRequirer {
118118
inner: TextRequirer,
119+
script_dir: PathBuf,
119120
path: Vec<String>,
120121
in_alias: bool,
121122
}
122123

123124
#[cfg(all(feature = "embedded-stdlib", not(debug_assertions)))]
124125
impl EmbeddedRequirer {
125-
pub fn new() -> Self {
126+
pub fn new(script_dir: PathBuf) -> Self {
126127
Self {
127128
inner: TextRequirer::new(),
129+
script_dir,
128130
path: Vec::new(),
129131
in_alias: false,
130132
}
@@ -208,7 +210,11 @@ impl Require for EmbeddedRequirer {
208210
}
209211

210212
fn config(&self) -> io::Result<Vec<u8>> {
211-
Ok(format!(r#"{{"aliases":{{"rootbeer":"{EMBEDDED_SENTINEL}"}}}}"#).into_bytes())
213+
Ok(format!(
214+
r#"{{"aliases":{{"rootbeer":"{EMBEDDED_SENTINEL}","source":"{}"}}}}"#,
215+
self.script_dir.display()
216+
)
217+
.into_bytes())
212218
}
213219

214220
fn loader(&self, lua: &Lua) -> Result<Function> {

crates/rootbeer-core/src/lua/vm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn make_require_fn(
8282
{
8383
let default_dir = std::path::PathBuf::from(env!("ROOTBEER_LUA_DIR"));
8484
if lua_dir == default_dir {
85-
return lua.create_require_function(EmbeddedRequirer::new());
85+
return lua.create_require_function(EmbeddedRequirer::new(script_dir));
8686
}
8787
}
8888

0 commit comments

Comments
 (0)