maxence-charriere / go-app

A package to build progressive web apps with Go programming language and WebAssembly.

Home Page:https://go-app.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FuncOf return value

alvarolm opened this issue · comments

I need to return as string from an FuncOf, so far I have tried with:

app.FuncOf(func(this app.Value, args []app.Value) any {
				return app.ValueOf("mystring")
})

but it crashes with:

panic: ValueOf: invalid value
wasm_exec.js:22
wasm_exec.js:22 goroutine 7 [running]:
wasm_exec.js:22 syscall/js.ValueOf({0x788a0, 0x14f2990})
wasm_exec.js:22 /home/alvarolm/dev/globaldep/go/src/syscall/js/js.go:209 +0xf6
wasm_exec.js:22 syscall/js.Value.Set({{}, 0x7ff80001000001a0, 0x14e0ad8}, {0x8a7a8, 0x6}, {0x788a0, 0x14f2990})
wasm_exec.js:22 /home/alvarolm/dev/globaldep/go/src/syscall/js/js.go:306 +0x8
wasm_exec.js:22 syscall/js.handleEvent()
wasm_exec.js:22 /home/alvarolm/dev/globaldep/go/src/syscall/js/func.go:103 +0x27

any help is appreciated

If you are wanting to pass back a string to the calling javascript, you don't need to use app.ValueOf

app.Window().Set("customFunction", app.FuncOf(func(this app.Value, args []app.Value) any {
    return "hello world"
}))

Calling from console:
image

Unless there is something more complex you are trying to do..

thanks! @mlctrez I was following the syscall/js logic for some reason.