Open wwwAngHua opened 8 months ago
package main
import (
"fmt"
"os"
wasmer "github.com/wasmerio/wasmer-go/wasmer"
)
func main() {
wasmBytes, _ := os.ReadFile("test.wasm")
engine := wasmer.NewEngine()
store := wasmer.NewStore(engine)
// Compiles the module
module, _ := wasmer.NewModule(store, wasmBytes)
// Instantiates the module
importObject := wasmer.NewImportObject()
instance, _ := wasmer.NewInstance(module, importObject)
// Gets the `sum` exported function from the WebAssembly instance.
sum, _ := instance.Exports.GetFunction("sum")
// Calls that exported function with Go standard values. The WebAssembly
// types are inferred and values are casted automatically.
result, _ := sum(5, 37)
fmt.Println(result) // 42!
}
~/study/wasm go run main.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x10038efbd]
goroutine 1 [running]:
main.main()
/Users/wanghua/study/wasm/main.go:24 +0x9d
exit status 2
Problem description:
I used tinygo to compile a wasm file, and an error occurred when I used wasmer-go to read, compile and execute the file again.
Steps to reproduce
main.go
wasm.go
Expected behavior
The sum function exists and it should return the correct result.
Actual behavior
JavaScript
Output: Uncaught TypeError: window.sum is not a function at calculate (index.html:23:31) at HTMLButtonElement.onclick(index.html:36:35)