Skip to content

Latest commit

 

History

History
51 lines (38 loc) · 763 Bytes

05-call-functions-go.md

File metadata and controls

51 lines (38 loc) · 763 Bytes

05-call-functions-go

Create a new project with source code

mkdir 05-call-functions-go
cd 05-call-functions-go
go mod init call-functions-go
touch main.go
package main

// ✋ make this function callable from host
//export add
func add(x int, y int) int {
  return x + y
}

func main() {}

Build

tinygo build -o main.wasm -target wasi ./main.go

ls -lh *.wasm

Run: call the function `add``

Ref https://wasmedge.org/docs/start/build-and-run/cli/

wasmedge --reactor main.wasm add 38 4

Add an hello function

//export hello
func hello(name string) string {
  return "hello " + name
}

Build, then, run: call the function hello

wasmedge --reactor main.wasm hello "Bob"