-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (36 loc) · 915 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"wasmgo/emscripten"
"wasmgo/types"
)
//go:generate go build -buildmode=plugin -o /Users/shang/go/src/wasmgo/build/darwin/network.so /Users/shang/go/src/wasmgo/plugin/network
//go:generate go build
//go:generate go build -buildmode=c-archive -o build/darwin/wasm.a
func main() {
name := flag.String("n", "_main", "wasm method name")
file := flag.String("f", "", "wasm file name ")
debug := flag.Bool("v", false, "open debug mode (-v open)")
flag.Parse()
args := flag.Args()
if *debug != true {
log.SetOutput(ioutil.Discard)
}
if *file != "" {
var vm types.VM = &emscripten.EMVM{}
vm.Init()
p := vm.LoadExecFile(*file)
result := vm.InvokeMethod(p, *name, args...)
fmt.Printf("result= %d \n", result)
} else {
flag.PrintDefaults()
}
defer func() {
if err := recover(); err != nil {
fmt.Println("参数错误")
}
}()
}