wasmerio / wasmer-go

🐹🕸️ WebAssembly runtime for Go
https://pkg.go.dev/github.com/wasmerio/wasmer-go
MIT License
2.8k stars 161 forks source link

GetFunction Missing 4 argument(s) when calling the function #365

Open rfyiamcool opened 1 year ago

rfyiamcool commented 1 year ago

Summary

happen error

GetFunction Missing 4 argument(s) when calling the function; Expected 5 argument(s), received 1

Additional details

I use the code to build wasm by tinygo.

package main

func main() {
}

//go:export add
func Add(a, b int) int {
    return a + b
}

//go:export replace
func Replace(a string) string {
    return a + "..."
}

go code

package main

import (
    "fmt"
    "io/ioutil"

    wasmer "github.com/wasmerio/wasmer-go/wasmer"
)

func main() {
    wasmBytes, _ := ioutil.ReadFile("module.wasm")

    engine := wasmer.NewEngine()
    store := wasmer.NewStore(engine)

    // Compiles the module
    module, err := wasmer.NewModule(store, wasmBytes)
    if err != nil {
        panic(err)
    }

    wasiEnv, _ := wasmer.NewWasiStateBuilder("wasi-program").CaptureStdout().CaptureStderr().Finalize()

    importObject, err := wasiEnv.GenerateImportObject(store, module)
    if err != nil {
        panic(err)
    }
    instance, err := wasmer.NewInstance(module, importObject)
    if err != nil {
        panic(err)
    }

    addfunc, _ := instance.Exports.GetFunction("add")
    result, _ := addfunc(1, 3)
    fmt.Println(result)

    replace, _ := instance.Exports.GetFunction("replace")
    result, err = replace("aaa")
    fmt.Println(result, err)
}

the function add run successfully, but function replace failed to run.

4
<nil> Missing 4 argument(s) when calling the function; Expected 5 argument(s), received 1
dullduck commented 1 year ago

same question