get reading input up and running
This commit is contained in:
parent
5b2fd5e2d7
commit
b7ff0eda80
|
@ -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
|
||||
|
|
|
@ -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?
|
||||
|
|
Binary file not shown.
|
@ -128,7 +128,7 @@ pub async fn do_io (msgs: Vec<MsgOut>) -> Vec<MsgIn> {
|
|||
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<MsgIn> = serde_json::from_str(inbox.as_str()).expect("response from js should be valid");
|
||||
if !inbox.is_empty() {
|
||||
log("ludus received messages".to_string());
|
||||
|
|
Loading…
Reference in New Issue
Block a user