-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
45 lines (35 loc) · 744 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
45
package main
import (
"fmt"
"github.com/skius/stringlang/cmd/stringlang/repl"
"syscall/js"
)
type wasm struct {
inChan chan<- string
}
// Receives input from wasm and forwards it to the JSTerminal
func (w *wasm) input(s string) {
w.inChan <- s
}
func wrapperInput(w *wasm) js.Func {
jsonFunc := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
if len(args) != 1 {
return "Invalid no of arguments passed"
}
input := args[0].String()
w.input(input)
return nil
})
return jsonFunc
}
func main() {
fmt.Println("Running!")
w := new(wasm)
inCh := make(chan string, 1)
w.inChan = inCh
js.Global().Set("SLInput", wrapperInput(w))
t := NewJSTerminal(inCh)
r := repl.Init(t)
r.Run()
<-make(chan bool)
}