add functions
This commit is contained in:
5 files changed
+244
-73
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
wasmgo "github.com/vedhavyas/wasm"
|
||||
@@ -12,7 +13,11 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err := b.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
init, done := make(chan bool), make(chan error)
|
||||
go b.Run(init, done)
|
||||
<-init
|
||||
res, err := b.CallFunc("printWasm", &[]interface{}{"success call"})
|
||||
fmt.Println(res, err)
|
||||
err = <-done
|
||||
fmt.Println("wasm exited", err)
|
||||
}
|
||||
+7
-5
@@ -7,17 +7,19 @@ import (
|
||||
"syscall/js"
|
||||
)
|
||||
|
||||
// TODO: log seems to cause an issue
|
||||
func printWasm(this js.Value, v []js.Value) interface{} {
|
||||
fmt.Println("Hello from WASM", v)
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
c := make(chan struct{}, 0)
|
||||
fmt.Println("WASM Go Initialized")
|
||||
ch := make(chan bool)
|
||||
//fmt.Println("WASM Go Initialized")
|
||||
|
||||
// register functions
|
||||
js.Global().Set("printWasm", js.FuncOf(printWasm))
|
||||
fmt.Println("Done...")
|
||||
<-c
|
||||
fun := js.FuncOf(printWasm)
|
||||
js.Global().Set("printWasm", fun)
|
||||
//fmt.Println("Done...")
|
||||
<-ch
|
||||
}
|
||||
Binary file not shown.
Reference in new issue
Block a user