Luau files loaded by path can't be required because the requiring context cannot be reset:
// src/main.rs
let lua = Lua::new()
lua.load(Path::new("asset/main.luau")).exec()?;
-- asset/main.luau
const second = require("./second"); -- error thrown here
Results in:
Error: runtime error: error requiring module "./second": could not reset to requiring context
stack traceback:
[C]: in ?
[C]: in function 'proxyrequire'
__mlua_require:13: in function <__mlua_require:1>
asset/main.luau:1: in function <asset/main.luau:1>
Digging in a bit, it seems like impl AsChunk for &Path and FsRequirer don't agree on the module naming convention. FsRequirer.reset() attempts to resolve asset/main.luau, but fails because it seems to expect a path without extension. impl AsChunk for &Path, meanwhile, leaves the extension intact.
There are workarounds, like loading the file bytes yourself, but this seems like the most obvious way to load luau files. It fails consistently with a very cryptic message from deep inside the luau VM.
Luau files loaded by path can't be required because the requiring context cannot be reset:
Results in:
Digging in a bit, it seems like
impl AsChunk for &PathandFsRequirerdon't agree on the module naming convention.FsRequirer.reset()attempts to resolveasset/main.luau, but fails because it seems to expect a path without extension.impl AsChunk for &Path, meanwhile, leaves the extension intact.There are workarounds, like loading the file bytes yourself, but this seems like the most obvious way to load luau files. It fails consistently with a very cryptic message from deep inside the luau VM.