go-wasm/simple/prog/main.go

28 lines
465 B
Go
Raw Normal View History

2019-08-06 16:03:11 +03:00
// +build js,wasm
package main
import (
"fmt"
"syscall/js"
)
2019-08-20 04:13:53 +03:00
// TODO: log seems to cause an issue
2019-08-20 22:20:20 +03:00
func addition(this js.Value, args []js.Value) interface{} {
fmt.Println("In WASM", args)
a, b := args[0].Int(), args[1].Int()
return a + b
2019-08-06 16:03:11 +03:00
}
func main() {
2019-08-20 04:13:53 +03:00
ch := make(chan bool)
2019-08-07 13:47:59 +03:00
// register functions
2019-08-20 22:20:20 +03:00
fun := js.FuncOf(addition)
js.Global().Set("addition", fun)
res := js.Global().Get("proxy").Invoke(1, 2)
fmt.Printf("1 + 2 = %d\n", res.Int())
2019-08-20 04:13:53 +03:00
<-ch
2019-08-06 16:03:11 +03:00
}