- Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiris-wasm.go
49 lines (44 loc) · 1.5 KB
/
iris-wasm.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
46
47
48
49
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package main
import (
"bytes"
"fmt"
"html"
"strings"
"syscall/js"
"github.com/asciian/iris/runtime"
"github.com/asciian/iris/runtime/ilos/instance"
)
funceval(sstring) string {
r:=strings.NewReader(s)
w:=new(bytes.Buffer)
runtime.TopLevel.StandardInput=instance.NewStream(r, nil)
runtime.TopLevel.StandardOutput=instance.NewStream(nil, w)
runtime.TopLevel.ErrorOutput=instance.NewStream(nil, w)
runtime.TopLevel.Function.Set(instance.NewSymbol("READ"), nil)
runtime.TopLevel.Function.Set(instance.NewSymbol("READ-LINE"), nil)
runtime.TopLevel.Function.Set(instance.NewSymbol("READ-CHAR"), nil)
p, err:=runtime.Read(runtime.TopLevel)
iferr!=nil {
fmt.Fprint(w, html.EscapeString(err.String()))
returnw.String()
}
e, err:=runtime.Eval(runtime.TopLevel, p)
iferr!=nil {
fmt.Fprint(w, html.EscapeString(err.String()))
returnw.String()
}
fmt.Fprint(w, html.EscapeString(e.String()))
returnw.String()
}
funcmain() {
input:=js.Global.Get("document").Call("getElementById", "input")
button:=js.Global.Get("document").Call("getElementById", "button")
output:=js.Global.Get("document").Call("getElementById", "output")
button.Call("addEventListener", "click", js.NewCallback(func(args []js.Value) {
output.Set("value", eval(input.Get("value").String()))
}))
select {}
}