diff --git a/imports.go b/imports.go index 8c6d464..b53019e 100644 --- a/imports.go +++ b/imports.go @@ -98,7 +98,9 @@ func getRandomData(ctx unsafe.Pointer, sp int32) { //export stringVal func stringVal(ctx unsafe.Pointer, sp int32) { - panic("stringVal") + b := getBridge(ctx) + str := b.loadString(sp + 8) + b.storeValue(sp+24, str) } //export valueGet @@ -212,17 +214,20 @@ func valuePrepareString(ctx unsafe.Pointer, sp int32) { val := b.loadValue(sp + 8) var str string if val != nil { - str = val.(string) + str = fmt.Sprint(val) } b.storeValue(sp+16, str) b.setInt64(sp+24, int64(len(str))) - fmt.Println("valuePrepareString", val, str) + fmt.Println("valuePrepareString", val) } //export valueLoadString 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 diff --git a/simple/caller/main.go b/simple/caller/main.go index 6ca6b2e..f1a8765 100644 --- a/simple/caller/main.go +++ b/simple/caller/main.go @@ -16,7 +16,7 @@ func main() { init, done := make(chan bool), make(chan error) go b.Run(init, done) <-init - res, err := b.CallFunc("printWasm", &[]interface{}{"success call"}) + res, err := b.CallFunc("printWasm", &[]interface{}{"Hello from Go"}) fmt.Println(res, err) err = <-done fmt.Println("wasm exited", err) diff --git a/simple/prog/main.go b/simple/prog/main.go index 57fd7d9..04fba53 100644 --- a/simple/prog/main.go +++ b/simple/prog/main.go @@ -9,17 +9,16 @@ import ( // TODO: log seems to cause an issue func printWasm(this js.Value, v []js.Value) interface{} { - fmt.Println("Hello from WASM", v) - return nil + fmt.Println(v[0].String()) + return "Hello from WASM" } func main() { ch := make(chan bool) - //fmt.Println("WASM Go Initialized") + fmt.Println("WASM-Go Initialized") // register functions fun := js.FuncOf(printWasm) js.Global().Set("printWasm", fun) - //fmt.Println("Done...") <-ch } diff --git a/simple/prog/main.wasm b/simple/prog/main.wasm index 6960b85..e244d4b 100755 Binary files a/simple/prog/main.wasm and b/simple/prog/main.wasm differ