diff options
| author | Alexander M Pickering <alex@cogarr.net> | 2024-12-22 21:30:49 -0600 |
|---|---|---|
| committer | Alexander M Pickering <alex@cogarr.net> | 2024-12-22 21:30:49 -0600 |
| commit | 8fd93fad84e043def785e594b4745e56c88c5d48 (patch) | |
| tree | 1c0dbb0070a660f52c5a0844f1d564af04d44914 | |
| parent | 00a3451004d664a5386f3750540facddc0d2686b (diff) | |
| download | ggj25-8fd93fad84e043def785e594b4745e56c88c5d48.tar.gz ggj25-8fd93fad84e043def785e594b4745e56c88c5d48.tar.bz2 ggj25-8fd93fad84e043def785e594b4745e56c88c5d48.zip | |
Start work on getting javascript to work
| -rw-r--r-- | Makefile | 5 | ||||
| -rw-r--r-- | ggj25/.gitignore | 1 | ||||
| -rw-r--r-- | src/js_bridge.js | 54 | ||||
| -rw-r--r-- | src/main.lua | 14 |
4 files changed, 32 insertions, 42 deletions
@@ -49,3 +49,8 @@ $(test_lua) : spec/%.lua : src/%.lua $(test_moon) : spec/%.lua : src/%.moon $(MOONC) -p $< > $@ + +$(built_js) : data/%.lua : src/%.js + echo "return [=====[" > $@ + cat $< >> $@ + echo "]=====]" >> $@ diff --git a/ggj25/.gitignore b/ggj25/.gitignore new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/ggj25/.gitignore @@ -0,0 +1 @@ +* diff --git a/src/js_bridge.js b/src/js_bridge.js index 2d32739..a9c8873 100644 --- a/src/js_bridge.js +++ b/src/js_bridge.js @@ -1,54 +1,24 @@ var s = document.createElement('script'); +var PEER = {}; s.setAttribute('src','https://unpkg.com/peerjs@1.5.2/dist/peerjs.min.js'); document.body.appendChild(s); function genRanHex(size) { return Array.apply(null,Array(size)).map(() => Math.floor(Math.random() * 16).toString(16)).join(''); } -PEER = {} -PEER.event_queue = {} -PEER.peers = {} -PEER.message_queue = {} -PEER["create"] = function(name, options) { - var peer = new Peer(name, options) - PEER.peers[name] = peer -} +PEER.event_queue = {}; +PEER.peers = {}; +PEER.message_queue = {}; +PEER.create = function(name, options) { + var peer = new Peer(name, options); + PEER.peers[name] = peer; +}; +/* PEER["on"] = function(name, e, message) { - PEER.peers[name].on(e, function(conn) { - PEER.message_queue.push(message) + PEER.peers[name].on(e, function(data) { + PEER.message_queue.push({"message":message, "data":data}) } } PEER["connect"] = function(name, id, options) { PEER.peers[name].connect(id, options) } -var peer = new Peer("ANGRY_ADVENTURE_" + GLOBAL.lobby_id, {"debug": 3}); -var peer_id = null; -var poo = peer.on('open', function(id) { - console.log('My peer ID is: ' + id); - peer.on("connection",function(conn){ - console.log("Got a connection!") - GLOBAL.connections[conn.peer] = conn - conn.send("Hello!") - GLOBAL.message_queue.push({ - "msg": "data", - "peer": conn.peer, - "data": '{"msg":"player_joined"}' - }) - conn.on("data",function(data){ - console.log("Got some data from a peer!:" + data) - GLOBAL.message_queue.push({ - "msg": "data", - "peer": conn.peer, - "data": data - }) - }) - conn.on("error",function(err){ - console.log("Error on a connection:" + err) - GLOBAL.message_queue.push({ - "msg": "error", - "peer": conn.peer, - "err": err - }) - }) - }) - GLOBAL.peer_id = id; -}); +*/ diff --git a/src/main.lua b/src/main.lua index e69de29..176cddc 100644 --- a/src/main.lua +++ b/src/main.lua @@ -0,0 +1,14 @@ + +print("Hello, world!") + +am.eval_js("console.log('Hello, js!')") + +local win = am.window{ + title = "Hi", + width = 1280, + height = 720, + clear_color = vec4(0.8, 0.8, 0.3, 1) +} +print("about to pcall") +local a,b = pcall(am.eval_js, require("js_bridge")) +print("done with pcall", a,b) |
