node_wasm.mx raw
1 //:build wasm
2
3 package node
4
5 import (
6 "git.smesh.lol/musiquay/web/common/jsbridge/callback"
7 "unsafe"
8 )
9
10 //:wasmimport bridge node_on_line
11 func wasmOnLine(cbID int32)
12
13 //:wasmimport bridge node_on_close
14 func wasmOnClose(cbID int32)
15
16 //:wasmimport bridge node_write_line
17 func wasmWriteLine(ptr *byte, length int32, capacity int32)
18
19 //:wasmimport bridge node_write_err
20 func wasmWriteErr(ptr *byte, length int32, capacity int32)
21
22 //:wasmimport bridge node_exit
23 func wasmExit(code int32)
24
25 //:wasmimport bridge node_now_seconds
26 func wasmNowSeconds() (n int64)
27
28 func OnLine(fn func(string)) {
29 wasmOnLine(callback.RegisterS(fn))
30 }
31
32 func OnClose(fn func()) {
33 wasmOnClose(callback.Register0(fn))
34 }
35
36 func WriteLine(s string) {
37 wasmWriteLine(unsafe.StringData(s), int32(len(s)), int32(len(s)))
38 }
39
40 func WriteErr(s string) {
41 wasmWriteErr(unsafe.StringData(s), int32(len(s)), int32(len(s)))
42 }
43
44 func Exit(code int32) {
45 wasmExit(code)
46 }
47
48 func NowSeconds() (n int64) {
49 return wasmNowSeconds()
50 }
51