diff --git a/assets/test_prelude.ld b/assets/test_prelude.ld index 9e762fd..1a6271c 100644 --- a/assets/test_prelude.ld +++ b/assets/test_prelude.ld @@ -4,6 +4,7 @@ box console = [] box input = "" box fetch_outbox = "" box fetch_inbox = () +box keys_down = [] & the very base: know something's type fn type { @@ -1282,19 +1283,39 @@ fn request_fetch! { } } -fn fetch! { +fn fetch { "Requests the contents of the URL passed in. Returns a result tuple of `(:ok, {contents})` or `(:err, {status code})`." (url) -> { let pid = self () - spawn! (fn () -> { - print! ("spawning fetch request in", self ()) - request_fetch! (pid, url) - }) - let out = receive { + spawn! (fn () -> request_fetch! (pid, url)) + receive { + (:reply, response) -> response + } + } +} + +fn input_reader! { + (pid as :keyword) -> { + if empty? (unbox (input)) + then { + yield! () + input_reader! (pid) + } + else { + send (pid, (:reply, unbox (input))) + store! (input, "") + } + } +} + +fn read_input { + "Waits until there is input in the input buffer, and returns it once there is." + () -> { + let pid = self () + spawn! (fn () -> input_reader! (pid)) + receive { (:reply, response) -> response } - print! ("received response: {out}") - out } } @@ -1309,16 +1330,18 @@ fn fetch! { flush! & wip actor functions - link! + & link! & shared memory w/ rust console input fetch_outbox fetch_inbox + keys_down & a fetch fn - fetch! + fetch + read_input abs abs diff --git a/may_2025_thoughts.md b/may_2025_thoughts.md index 2f5fe50..d870086 100644 --- a/may_2025_thoughts.md +++ b/may_2025_thoughts.md @@ -1196,14 +1196,14 @@ After that: - [x] `input` * [x] js->rust->ludus buffer (in Rust code) * [ ] ludus abstractions around this buffer (in Ludus code) - - [ ] `fetch`--request & response - * [ ] request: ludus->rust->js->net - * [ ] response: js->rust->ludus + - [x] `fetch`--request & response + * [x] request: ludus->rust->js->net + * [x] response: js->rust->ludus - [ ] `keyboard` * [ ] still working on how to represent this * [ ] hook this up to `web.ludus.dev` * [ ] do some integration testing - - [ ] do synchronous programs still work? + - [x] do synchronous programs still work? - [ ] animations? - [ ] read inputs? - [ ] load url text? diff --git a/pkg/rudus_bg.wasm b/pkg/rudus_bg.wasm index a764218..47ef0bf 100644 Binary files a/pkg/rudus_bg.wasm and b/pkg/rudus_bg.wasm differ diff --git a/src/io.rs b/src/io.rs index e6e2b2c..aba5248 100644 --- a/src/io.rs +++ b/src/io.rs @@ -128,7 +128,7 @@ pub async fn do_io (msgs: Vec) -> Vec { Err(_) => return vec![] }; let inbox = inbox.as_string().expect("response should be a string"); - log(format!("got a message: {inbox}")); + // log(format!("got a message: {inbox}")); let inbox: Vec = serde_json::from_str(inbox.as_str()).expect("response from js should be valid"); if !inbox.is_empty() { log("ludus received messages".to_string());