Skip to content

Commit 61a2141

Browse files
committed
Don't panic when fourth library searcher does not exists.
When disabling C modules, we remove the last two searchers (C & C all-in-one). In Pluto the C searches may not exist by design, in this case check that 4th searcher is present before removing it. Closes #530
1 parent dea38f2 commit 61a2141

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/state.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,7 +2062,6 @@ impl Lua {
20622062
WeakLua(XRc::downgrade(&self.raw))
20632063
}
20642064

2065-
// Luau version located in `luau/mod.rs`
20662065
#[cfg(not(feature = "luau"))]
20672066
fn disable_c_modules(&self) -> Result<()> {
20682067
let package: Table = self.globals().get("package")?;
@@ -2085,7 +2084,9 @@ impl Lua {
20852084

20862085
// The third and fourth searchers looks for a loader as a C library
20872086
searchers.raw_set(3, loader)?;
2088-
searchers.raw_remove(4)?;
2087+
if searchers.raw_len() >= 4 {
2088+
searchers.raw_remove(4)?;
2089+
}
20892090

20902091
Ok(())
20912092
}

src/state/raw.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ impl RawLua {
296296
if is_safe {
297297
let curr_libs = (*self.extra.get()).libs;
298298
if (curr_libs ^ (curr_libs | libs)).contains(StdLib::PACKAGE) {
299-
mlua_expect!(self.lua().disable_c_modules(), "Error during disabling C modules");
299+
mlua_expect!(self.lua().disable_c_modules(), "Error disabling C modules");
300300
}
301301
}
302302
#[cfg(feature = "luau")]

0 commit comments

Comments
 (0)