2019-08-06 16:03:11 +03:00
|
|
|
// +build js,wasm
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-08-20 23:47:40 +03:00
|
|
|
"log"
|
2019-08-06 16:03:11 +03:00
|
|
|
"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{} {
|
2019-08-20 23:47:40 +03:00
|
|
|
log.Println("In WASM", args)
|
2019-08-20 22:20:20 +03:00
|
|
|
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)
|
2019-08-20 23:47:40 +03:00
|
|
|
log.Printf("1 + 2 = %d\n", res.Int())
|
2019-08-20 04:13:53 +03:00
|
|
|
<-ch
|
2019-08-06 16:03:11 +03:00
|
|
|
}
|