main.go 523 字节
Newer Older
P
Phodal Huang 已提交
1 2 3
package main

import (
P
Phodal Huang 已提交
4 5
	"encoding/json"
	"syscall/js"
6
	"wasm/wadapter"
P
Phodal Huang 已提交
7 8
)

P
Phodal Huang 已提交
9 10 11 12 13 14 15 16 17
func registerCallbacks() {
	js.Global().Set("compileCode", js.FuncOf(CompileCodeCallback))
}

func main() {
	c := make(chan struct{}, 0)
	registerCallbacks()
	<-c
}
P
Phodal Huang 已提交
18

P
Phodal Huang 已提交
19 20 21
func CompileCodeCallback(value js.Value, args []js.Value) interface{} {
	callback := args[len(args)-1:][0]
	message := args[0].String()
P
Phodal Huang 已提交
22

23
	results := wadapter.CompileCode(message)
P
Phodal Huang 已提交
24 25 26 27

	identModel, _ := json.Marshal(results)
	callback.Invoke(js.Null(), string(identModel))
	return nil
P
Phodal Huang 已提交
28
}
P
Phodal Huang 已提交
29