on master help sign in
commit078ba3f24ccafceafc131bf20c308dd25b00aef7 authoriko <mail@iko.soy> dateMon 28 Oct 2024, 20:26 (2 years ago) parent995260a
10 files changed+59−35
flake.lock+15−15 hello.nock index.html−12 nock/hello.hoon+5−1 nock/hello.nock wock-web/Cargo.toml+8−2 wock-web/build.sh+1−1 wock-web/hello.nock wock-web/index.html+1 wock-web/src/lib.rs+29−4
flake.lock+15−15
@@ -6,11 +6,11 @@
66 "rust-analyzer-src": "rust-analyzer-src"
77 },
88 "locked": {
9− "lastModified": 1724221791,
10− "narHash": "sha256-mKX67QPnUybOopVph/LhOV1G/H4EvPxDIfSmbufrVdA=",
9+ "lastModified": 1730010749,
10+ "narHash": "sha256-UBckyKItSD0z50+3YQOqfOuyvUI7UjPHiLbOPFUolqo=",
1111 "owner": "nix-community",
1212 "repo": "fenix",
13− "rev": "e88b38a5a3834e039d413a88f8150a75ef6453ef",
13+ "rev": "5fa09829e74070c1e83b2aaa50b71bbc6da3f37c",
1414 "type": "github"
1515 },
1616 "original": {
@@ -24,11 +24,11 @@
2424 "systems": "systems"
2525 },
2626 "locked": {
27− "lastModified": 1710146030,
28− "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
27+ "lastModified": 1726560853,
28+ "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=",
2929 "owner": "numtide",
3030 "repo": "flake-utils",
31− "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
31+ "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a",
3232 "type": "github"
3333 },
3434 "original": {
@@ -38,11 +38,11 @@
3838 },
3939 "nixpkgs": {
4040 "locked": {
41− "lastModified": 1723991338,
42− "narHash": "sha256-Grh5PF0+gootJfOJFenTTxDTYPidA3V28dqJ/WV7iis=",
41+ "lastModified": 1729880355,
42+ "narHash": "sha256-RP+OQ6koQQLX5nw0NmcDrzvGL8HDLnyXt/jHhL1jwjM=",
4343 "owner": "nixos",
4444 "repo": "nixpkgs",
45− "rev": "8a3354191c0d7144db9756a74755672387b702ba",
45+ "rev": "18536bf04cd71abd345f9579158841376fdd0c5a",
4646 "type": "github"
4747 },
4848 "original": {
@@ -54,11 +54,11 @@
5454 },
5555 "nixpkgs_2": {
5656 "locked": {
57− "lastModified": 1723637854,
58− "narHash": "sha256-med8+5DSWa2UnOqtdICndjDAEjxr5D7zaIiK4pn0Q7c=",
57+ "lastModified": 1729880355,
58+ "narHash": "sha256-RP+OQ6koQQLX5nw0NmcDrzvGL8HDLnyXt/jHhL1jwjM=",
5959 "owner": "NixOS",
6060 "repo": "nixpkgs",
61− "rev": "c3aa7b8938b17aebd2deecf7be0636000d62a2b9",
61+ "rev": "18536bf04cd71abd345f9579158841376fdd0c5a",
6262 "type": "github"
6363 },
6464 "original": {
@@ -77,11 +77,11 @@
7777 "rust-analyzer-src": {
7878 "flake": false,
7979 "locked": {
80− "lastModified": 1724153119,
81− "narHash": "sha256-WxpvDJDttkINkXmUA/W5o11lwLPYhATAgu0QUAacZ2g=",
80+ "lastModified": 1729923686,
81+ "narHash": "sha256-Tc+5E/UmjpXlYGQQ6X2nGDv6J6VQgZ+pVOJLcNCIVQc=",
8282 "owner": "rust-lang",
8383 "repo": "rust-analyzer",
84− "rev": "3723e5910c14f0ffbd13de474b8a8fcc74db04ce",
84+ "rev": "26d2fbaef2d68a2fccf55d725915188c2634439a",
8585 "type": "github"
8686 },
8787 "original": {
hello.nock

Binary file not shown.

index.htmldeleted−12
@@ -1,12 +0,0 @@
1−<!DOCTYPE html>
2−
3−<html>
4−<head>
5− <meta charset="UTF-8" />
6− <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
7−</head>
8−<body>
9− <script type="text/javascript" src="/result/nock.js"></script>
10− <script type="text/javascript" src="/script.js"></script>
11−</body>
12−</html>
nock/hello.hoon+5−1
@@ -1 +1,5 @@
1−|=(x=@t (crip (weld "Hello, " (trip x))))
1+|= name=@t
2+?+ name (crip (weld "Hello, " (trip name)))
3+ 'Curtis' 'Hello, daddy...'
4+ '' 'Hello, world!'
5+==
nock/hello.nock

Binary file not shown.

wock-web/Cargo.toml+8−2
@@ -21,11 +21,14 @@ nock = { path = "../nock" }
2121console_error_panic_hook = { version = "0.1.7", optional = true }
2222wasm-bindgen-futures = "0.4.45"
2323js-sys = "0.3.72"
24−gloo = "0.11.0"
2524
2625[dependencies.web-sys]
2726version = "0.3.72"
28−features = ['Headers', 'Request', 'RequestInit', 'RequestMode', 'Response', 'Window', 'Blob']
27+features = ['Headers', 'Request', 'RequestInit', 'RequestMode', 'Response', 'Window', 'Blob', 'Document', 'Element']
28+
29+[dependencies.gloo]
30+version = "0.11.0"
31+features = ['utils']
2932
3033[dev-dependencies]
3134wasm-bindgen-test = "0.3.34"
@@ -33,3 +36,6 @@ wasm-bindgen-test = "0.3.34"
3336[profile.release]
3437# Tell `rustc` to optimize for small code size.
3538opt-level = "s"
39+
40+[package.metadata.wasm-pack.profile.dev]
41+wasm-opt = ["-O", "--enable-bulk-memory"]
wock-web/build.sh+1−1
@@ -1,3 +1,3 @@
11#!/bin/sh
22
3−wasm-pack build --no-typescript --no-pack --target=web
3+wasm-pack build --no-typescript --no-pack --target=web --dev
wock-web/hello.nocknew file

Binary file not shown.

wock-web/index.html+1
@@ -4,6 +4,7 @@
44 </head>
55 <body>
66 <input id="input"></input>
7+ <div id="output"></div>
78 <script type="module" src="script.mjs?src=/hello.nock"></script>
89 </body>
910</html>
wock-web/src/lib.rs+29−4
@@ -2,6 +2,7 @@ mod utils;
22
33use std::rc::Rc;
44
5+use gloo::events::EventListener;
56use nock::{
67 cue::cue_bytes,
78 interpreter::{generate_interpreter_context, slam},
@@ -9,6 +10,7 @@ use nock::{
910};
1011use wasm_bindgen::prelude::*;
1112use wasm_bindgen_futures::JsFuture;
13+use web_sys::{Element, HtmlInputElement};
1214
1315#[wasm_bindgen]
1416extern "C" {
@@ -23,17 +25,40 @@ pub fn greet() {
2325 alert("Hello, wock-web!");
2426}
2527
28+static mut LISTENER: Option<EventListener> = None;
29+
2630#[wasm_bindgen]
2731pub async fn main(path: &str) {
2832 let nock = load_nock(path).await;
2933
3034 let mut ctx = generate_interpreter_context();
31− let bar = slam(&mut ctx, &nock, &Rc::new(Noun::from_bytes(b"Curtis"))).unwrap();
3235
33− let foo = bar.as_bytes().unwrap();
34− let qux = String::from_utf8(foo).unwrap();
36+ let document = gloo::utils::document();
37+ let input_element: web_sys::HtmlInputElement = document
38+ .get_element_by_id("input")
39+ .unwrap()
40+ .dyn_into()
41+ .unwrap();
42+ let output_el: Element = document.get_element_by_id("output").unwrap();
43+ unsafe {
44+ LISTENER = Some(EventListener::new(&input_element, "input", move |ev| {
45+ let el: HtmlInputElement = ev.target().unwrap().dyn_into().unwrap();
46+
47+ let bar = slam(
48+ &mut ctx,
49+ &nock,
50+ &Rc::new(Noun::from_bytes(el.value().as_bytes())),
51+ )
52+ .unwrap();
53+
54+ let foo = bar.as_bytes().unwrap();
55+ let qux = String::from_utf8(foo).unwrap();
56+
57+ output_el.set_inner_html(&*qux);
58+ }));
59+ }
3560
36− log(&*qux);
61+ // window.get_eleme
3762}
3863
3964pub async fn load_nock(path: &str) -> Rc<Noun> {