[doc] Update go example (#3065)
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
# Go
|
# Using WebAssembly from Go
|
||||||
|
|
||||||
Wasmtime [is available as a Go
|
Wasmtime [is available as a Go
|
||||||
Module](https://pkg.go.dev/github.com/bytecodealliance/wasmtime-go). This guide
|
Module](https://pkg.go.dev/github.com/bytecodealliance/wasmtime-go). This guide
|
||||||
@@ -15,6 +15,7 @@ First up you'll want to start a new module:
|
|||||||
$ mkdir hello-wasm
|
$ mkdir hello-wasm
|
||||||
$ cd hello-wasm
|
$ cd hello-wasm
|
||||||
$ go mod init hello-wasm
|
$ go mod init hello-wasm
|
||||||
|
$ go get github.com/bytecodealliance/wasmtime-go
|
||||||
```
|
```
|
||||||
|
|
||||||
Next, copy this example WebAssembly text module into your project. It exports a
|
Next, copy this example WebAssembly text module into your project. It exports a
|
||||||
@@ -39,11 +40,11 @@ func main() {
|
|||||||
store := wasmtime.NewStore(engine)
|
store := wasmtime.NewStore(engine)
|
||||||
module, err := wasmtime.NewModuleFromFile(engine, "gcd.wat")
|
module, err := wasmtime.NewModuleFromFile(engine, "gcd.wat")
|
||||||
check(err)
|
check(err)
|
||||||
instance, err := wasmtime.NewInstance(store, module, []*wasmtime.Extern{})
|
instance, err := wasmtime.NewInstance(store, module, []wasmtime.AsExtern{})
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
gcd := instance.GetExport("gcd").Func()
|
gcd := instance.GetExport(store, "gcd").Func()
|
||||||
val, err := gcd.Call(6, 27)
|
val, err := gcd.Call(store, 6, 27)
|
||||||
check(err)
|
check(err)
|
||||||
fmt.Printf("gcd(6, 27) = %d\n", val.(int32))
|
fmt.Printf("gcd(6, 27) = %d\n", val.(int32))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user