ceifa / wasmoon

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

Memory access out of bounds when using await #66

Closed Burperino closed 1 year ago

Burperino commented 1 year ago

I am trying to integrate lua in a project of mine, but it requires a lot of asynchronous code. I made a 'sleep' function to test whether working with asynchronous code would work. It is registered as a function, but when I run it it gives me a memory out of bounds error. The lua vm works fine. The function works in javascript.

vm.js: lua.global.set('sleep', sleep);

utils.js: const sleep = (m) => new Promise((r, rj) => setTimeout(r, m)); // Yes this is exported

test.lua: sleep(1000):await()

The error: wasm://wasm/000f64ae:1 RuntimeError: memory access out of bounds

If I don't include the :await() it works, but it doesn't wait for the promise to get resolved. print(sleep(1000)) results in js_promise

Did I do something wrong?

Thank you for your time.

ceifa commented 1 year ago

Can you make a minimal repro?

Burperino commented 1 year ago

It didn't appear in the minimal reproduction, so I think it was a problem in the bigger project. Anyway, thank you for your time.

CoreBytee commented 1 year ago

Did the bigger project include electron by any chance? The way I get the error is when electron calls a lua event callback function.

For example:

BrowserWindow:on(
    "ready-to-show",
    function ()
        -- Code that does not execute because of the error
    end
)
ceifa commented 1 year ago

@CoreBytee do you have a minimal repro?

CoreBytee commented 1 year ago

I will try to make one later next week