get reading input up and running

This commit is contained in:
Scott Richmond 2025-07-01 19:04:38 -04:00
parent 5b2fd5e2d7
commit b7ff0eda80
4 changed files with 38 additions and 15 deletions

View File

@ -4,6 +4,7 @@ box console = []
box input = "" box input = ""
box fetch_outbox = "" box fetch_outbox = ""
box fetch_inbox = () box fetch_inbox = ()
box keys_down = []
& the very base: know something's type & the very base: know something's type
fn 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})`." "Requests the contents of the URL passed in. Returns a result tuple of `(:ok, {contents})` or `(:err, {status code})`."
(url) -> { (url) -> {
let pid = self () let pid = self ()
spawn! (fn () -> { spawn! (fn () -> request_fetch! (pid, url))
print! ("spawning fetch request in", self ()) receive {
request_fetch! (pid, url) (:reply, response) -> response
}) }
let out = receive { }
}
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 (:reply, response) -> response
} }
print! ("received response: {out}")
out
} }
} }
@ -1309,16 +1330,18 @@ fn fetch! {
flush! flush!
& wip actor functions & wip actor functions
link! & link!
& shared memory w/ rust & shared memory w/ rust
console console
input input
fetch_outbox fetch_outbox
fetch_inbox fetch_inbox
keys_down
& a fetch fn & a fetch fn
fetch! fetch
read_input
abs abs
abs abs

View File

@ -1196,14 +1196,14 @@ After that:
- [x] `input` - [x] `input`
* [x] js->rust->ludus buffer (in Rust code) * [x] js->rust->ludus buffer (in Rust code)
* [ ] ludus abstractions around this buffer (in Ludus code) * [ ] ludus abstractions around this buffer (in Ludus code)
- [ ] `fetch`--request & response - [x] `fetch`--request & response
* [ ] request: ludus->rust->js->net * [x] request: ludus->rust->js->net
* [ ] response: js->rust->ludus * [x] response: js->rust->ludus
- [ ] `keyboard` - [ ] `keyboard`
* [ ] still working on how to represent this * [ ] still working on how to represent this
* [ ] hook this up to `web.ludus.dev` * [ ] hook this up to `web.ludus.dev`
* [ ] do some integration testing * [ ] do some integration testing
- [ ] do synchronous programs still work? - [x] do synchronous programs still work?
- [ ] animations? - [ ] animations?
- [ ] read inputs? - [ ] read inputs?
- [ ] load url text? - [ ] load url text?

Binary file not shown.

View File

@ -128,7 +128,7 @@ pub async fn do_io (msgs: Vec<MsgOut>) -> Vec<MsgIn> {
Err(_) => return vec![] Err(_) => return vec![]
}; };
let inbox = inbox.as_string().expect("response should be a string"); 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<MsgIn> = serde_json::from_str(inbox.as_str()).expect("response from js should be valid"); let inbox: Vec<MsgIn> = serde_json::from_str(inbox.as_str()).expect("response from js should be valid");
if !inbox.is_empty() { if !inbox.is_empty() {
log("ludus received messages".to_string()); log("ludus received messages".to_string());