My purpose is trying to use go wasm in Obsidian plugin.
make wasm
will generate md-monitor.wasm
file which is executed in Obsidian plugin.
There are two ways to execute wasm file:
- browser(Chrome);
- nodejs(Obsidian console or other electron app);
To execute wasm file in browser, please reference the file test/index.html
. For nodejs, please reference the file test/test_in_console.js
.
- export function:
js.Global().Set("jsPI", jsPI())
- call exported function:
WebAssembly.instantiate(content, go.importObject).then((ret) => { go.run(ret.instance); });
// call exported function which define in go module.
jsPI(3);
js.Global().Call("alert", "this is an alerting!")
v := js.Global().Get("app")
fmt.Println(v.Get("title").String())
fmt.Println(v.Call("getAppTitle", "").String())
- WASI