go-wasm/simple/prog/main.go

25 lines
387 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-07 13:47:59 +03:00
func printWasm(this js.Value, v []js.Value) interface{} {
2019-08-20 04:25:01 +03:00
fmt.Println(v[0].String())
return "Hello from WASM"
2019-08-06 16:03:11 +03:00
}
func main() {
2019-08-20 04:13:53 +03:00
ch := make(chan bool)
2019-08-20 04:25:01 +03:00
fmt.Println("WASM-Go Initialized")
2019-08-07 13:47:59 +03:00
// register functions
2019-08-20 04:13:53 +03:00
fun := js.FuncOf(printWasm)
js.Global().Set("printWasm", fun)
<-ch
2019-08-06 16:03:11 +03:00
}