ceifa / wasmoon

A real lua 5.4 VM with JS bindings made with webassembly
MIT License
496 stars 32 forks source link

Requiring module failed #79

Closed pureliumy closed 12 months ago

pureliumy commented 1 year ago

If the lua string contains require statement, doString will fail because it can't find the required module.

I tried to set a new package.path value, but it didn't work.

Could anyone know how to deal with this situation?

Thanks!

pureliumy commented 1 year ago

I noticed there is a -l option to include files when use CLI, and the internal method is factory.mountFile. I will have a try with it.

pureliumy commented 1 year ago

I noticed there is a -l option to include files when use CLI, and the internal method is factory.mountFile. I will have a try with it.

Failed. Both CLI and factory.mountFile.

ceifa commented 1 year ago

wasmoon is sandboxed by default. You need to mount the file into it before requiring as a module.

pureliumy commented 1 year ago

wasmoon is sandboxed by default. You need to mount the file into it before requiring as a module.

Kindly asking what is the correct way to mount the file, I tried factory.mountFile method, and it didn't work.

ceifa commented 1 year ago

Kindly asking what is the correct way to mount the file, I tried factory.mountFile method, and it didn't work.

Can you make a minimal repro? factory.mountFile should work just great.

raylu commented 1 year ago

I will say this was pretty confusing. I'm using it in the browser and I thought LuaEngine.doFile was just for CLI usage. since there are no docs, showing an example with mountFile would be very helpful!

Watunder commented 1 year ago

factory.mountFile with relative path name like this: https://gist.github.com/a5b17f4459f40022af518742719a2e20.git

hellpanderrr commented 9 months ago

You can write you own require function using javascript's fetch, so you can get by without mounting every import file, I described it here.