github.com/aykevl/tinygo@v0.5.0/src/examples/wasm/export/wasm.go (about)

     1  package main
     2  
     3  import (
     4  	"strconv"
     5  	"syscall/js"
     6  )
     7  
     8  func main() {
     9  }
    10  
    11  //go:export add
    12  func add(a, b int) int {
    13  	return a + b
    14  }
    15  
    16  //go:export update
    17  func update() {
    18  	document := js.Global().Get("document")
    19  	aStr := document.Call("getElementById", "a").Get("value").String()
    20  	bStr := document.Call("getElementById", "b").Get("value").String()
    21  	a, _ := strconv.Atoi(aStr)
    22  	b, _ := strconv.Atoi(bStr)
    23  	result := add(a, b)
    24  	document.Call("getElementById", "result").Set("value", result)
    25  }