Categorygithub.com/syumai/wasmexec
modulepackage
0.0.0-20200211181706-3f336d679081
Repository: https://github.com/syumai/wasmexec.git
Documentation: pkg.go.dev

# README

wasmexec

  • wasmexec is a utility to execute WebAssembly in Go with interface similar to WebAssembly.instantiateStreaming().
  • This package is using wagon as an interpreter of WebAssembly.

Usage

1. Create Wasm binary

  • multiply.wat
(module
  (import "go" "imultiply" (func $imultiply (param $a i32) (param $b i32) (result i32)))
  (func (export "multiply") (param $a i32) (param $b i32) (result i32)
    local.get $a
    local.get $b
    call $imultiply)
)
$ wat2wasm multiply.wat

2. Read Wasm binary and execute exported function

  • main.go
// 1. Open Wasm binary
f, _ := os.Open("exmaple.wasm")
defer f.Close()

// 2. Create ImportObject
importObject := wasmexec.ImportObject{
    "go": {
        "imultiply": func(a int, b int) int{
            return a * b
        },
    },
}

// 3. Initialize WebAssembly instance
inst, _ := wasmexec.InstantiateStreaming(f, importObject)

// 4. Call exported function
result, _ := inst.Call("multiply", uint64(2), uint64(3))
fmt.Println(result) // #=> 6

For details, please see examples/multiply.

Supported Features

  • import func
  • import global
  • import memory

License

MIT

Author

syumai

# Packages

No description provided by the author

# Functions

No description provided by the author
No description provided by the author

# Constants

# Structs

No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author