Skip to content

Can't require luau files loaded by path #735

Description

@dubrowgn

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions