node_wasm.mx raw

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