bidirectional communication
parent
fbfa1a0c93
commit
3351f3eb4b
13
imports.go
13
imports.go
|
@ -98,7 +98,9 @@ func getRandomData(ctx unsafe.Pointer, sp int32) {
|
||||||
|
|
||||||
//export stringVal
|
//export stringVal
|
||||||
func stringVal(ctx unsafe.Pointer, sp int32) {
|
func stringVal(ctx unsafe.Pointer, sp int32) {
|
||||||
panic("stringVal")
|
b := getBridge(ctx)
|
||||||
|
str := b.loadString(sp + 8)
|
||||||
|
b.storeValue(sp+24, str)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export valueGet
|
//export valueGet
|
||||||
|
@ -212,17 +214,20 @@ func valuePrepareString(ctx unsafe.Pointer, sp int32) {
|
||||||
val := b.loadValue(sp + 8)
|
val := b.loadValue(sp + 8)
|
||||||
var str string
|
var str string
|
||||||
if val != nil {
|
if val != nil {
|
||||||
str = val.(string)
|
str = fmt.Sprint(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
b.storeValue(sp+16, str)
|
b.storeValue(sp+16, str)
|
||||||
b.setInt64(sp+24, int64(len(str)))
|
b.setInt64(sp+24, int64(len(str)))
|
||||||
fmt.Println("valuePrepareString", val, str)
|
fmt.Println("valuePrepareString", val)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export valueLoadString
|
//export valueLoadString
|
||||||
func valueLoadString(ctx unsafe.Pointer, sp int32) {
|
func valueLoadString(ctx unsafe.Pointer, sp int32) {
|
||||||
panic("valueLoadString")
|
b := getBridge(ctx)
|
||||||
|
str := b.loadValue(sp + 8).(string)
|
||||||
|
sl := b.loadSlice(sp + 16)
|
||||||
|
copy(sl, str)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export scheduleTimeoutEvent
|
//export scheduleTimeoutEvent
|
||||||
|
|
|
@ -16,7 +16,7 @@ func main() {
|
||||||
init, done := make(chan bool), make(chan error)
|
init, done := make(chan bool), make(chan error)
|
||||||
go b.Run(init, done)
|
go b.Run(init, done)
|
||||||
<-init
|
<-init
|
||||||
res, err := b.CallFunc("printWasm", &[]interface{}{"success call"})
|
res, err := b.CallFunc("printWasm", &[]interface{}{"Hello from Go"})
|
||||||
fmt.Println(res, err)
|
fmt.Println(res, err)
|
||||||
err = <-done
|
err = <-done
|
||||||
fmt.Println("wasm exited", err)
|
fmt.Println("wasm exited", err)
|
||||||
|
|
|
@ -9,17 +9,16 @@ import (
|
||||||
|
|
||||||
// TODO: log seems to cause an issue
|
// TODO: log seems to cause an issue
|
||||||
func printWasm(this js.Value, v []js.Value) interface{} {
|
func printWasm(this js.Value, v []js.Value) interface{} {
|
||||||
fmt.Println("Hello from WASM", v)
|
fmt.Println(v[0].String())
|
||||||
return nil
|
return "Hello from WASM"
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ch := make(chan bool)
|
ch := make(chan bool)
|
||||||
//fmt.Println("WASM Go Initialized")
|
fmt.Println("WASM-Go Initialized")
|
||||||
|
|
||||||
// register functions
|
// register functions
|
||||||
fun := js.FuncOf(printWasm)
|
fun := js.FuncOf(printWasm)
|
||||||
js.Global().Set("printWasm", fun)
|
js.Global().Set("printWasm", fun)
|
||||||
//fmt.Println("Done...")
|
|
||||||
<-ch
|
<-ch
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue