summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-05-14 00:31:48 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-05-14 00:31:48 -0400
commit1ad8a2e0881751e7ca642a6dde503dd7b7c3604f (patch)
tree110143a4f35556dcdf3befa8c648b79ea8c826de /main.go
parent4db5a80ba314e584adafd0b0ea1db05d70200f6a (diff)
Send protobuf
Diffstat (limited to 'main.go')
-rw-r--r--main.go30
1 files changed, 22 insertions, 8 deletions
diff --git a/main.go b/main.go
index 23db83f9a..fc69fee59 100644
--- a/main.go
+++ b/main.go
@@ -1,11 +1,13 @@
-// To test: make && ./out/render test_input.js
package main
+//go:generate protoc --go_out=. msg.proto
//go:generate ./node_modules/.bin/parcel build --out-dir=dist/ --no-minify main.ts
//go:generate go-bindata -pkg $GOPACKAGE -o assets.go dist/
import (
+ "github.com/golang/protobuf/proto"
"github.com/ry/v8worker2"
+ "os"
)
func recv(msg []byte) []byte {
@@ -13,20 +15,32 @@ func recv(msg []byte) []byte {
return nil
}
-func main() {
- indexFn := "dist/main.js"
- data, err := Asset(indexFn)
+func loadAsset(w *v8worker2.Worker, path string) {
+ data, err := Asset(path)
if err != nil {
panic("asset not found")
}
- code := string(data)
+ err = w.Load(path, string(data))
+ if err != nil {
+ panic(err)
+ }
+}
+func main() {
worker := v8worker2.New(recv)
+ loadAsset(worker, "dist/main.js")
- // Load up index.js code.
- err = worker.Load(indexFn, code)
+ loadMsg := &Msg{
+ Kind: Msg_LOAD,
+ Argv: os.Args,
+ }
+ out, err := proto.Marshal(loadMsg)
if err != nil {
- println("Problem executing Javascript.")
panic(err)
}
+ err = worker.SendBytes(out)
+ if err != nil {
+ panic(err)
+ }
+
}