ceifa / wasmoon

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

[BUG] wrapper breaks sometimes #98

Closed ParadiseFallen closed 7 months ago

ParadiseFallen commented 7 months ago

const factory = new LuaFactory();
    const engine = await factory.createEngine();

    const fun = (number : number) => {
      return number * 2;
    }
    const fn = await engine.doString(`
      return function (jsFunction)
        return function ()
          return funcction ()
            print(jsFunction(1))
          end
        end
      end
    `);

    fn(fun)()();

so sometimes pass functions just not don't works

error is

glue.wasm:0x10a65 Uncaught (in promise) RuntimeError: memory access out of bounds
    at glue.wasm:0x10a65
    at glue.wasm:0x4b0a
    at glue.wasm:0x20594
    at c._luaL_newmetatable (index.js:1278:1)
    at c.ccall (index.js:1290:1)
    at LuaWasm.pointersToBeFreed [as luaL_newmetatable] (index.js:1540:1)
    at new FunctionTypeExtension (index.js:640:1)
    at createTypeExtension$4 (index.js:755:1)
    at new LuaEngine (index.js:1121:1)
    at LuaFactory.createEngine (index.js:1618:1)
tims-bsquare commented 7 months ago

I ran the following in engine.test.js several times and did not find an issue:

    it('paradisefallen', async () => {
        const engine = await getEngine()

        const fun = (num) => {
            return num * 2
        }
        const fn = await engine.doString(`
          return function (jsFunction)
            return function ()
              return function ()
                print(jsFunction(1))
              end
            end
          end
        `)

        fn(fun)()()
    })

v.18.18.0 - Tested with latest build that has my fix to doString and with the previous release before that PR

ParadiseFallen commented 7 months ago

@tims-bsquare it breaks on 1.15.0. will check on newer version