feat(launcher): Process.*, Http.save_to/received/expected, App.window_hide/show
Process.spawn/poll/kill/free - non-blocking child processes with no shell: posix_spawn on macOS (process.ll), CreateProcessW with MSVC-quoted arguments and no console window on Windows (process_win.ll), linked only when a program uses Process.*. Http.save_to streams a response body into a file (NSURLSession with a run-time delegate class on macOS, the WinHTTP read loop on Windows); Http.received / Http.expected report progress while it is pending. Freeing a pending request cancels it and parks the slot until the worker has finished. App.window_hide / App.window_show take the game's window off the screen and back without closing it; the run goes on while hidden. Docs, examples, tests and a changeset. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
c1db0d71ed
commit
43d5eb5b88
31 changed files with 89274 additions and 86727 deletions
|
|
@ -4,6 +4,6 @@ title: Http
|
|||
order: 8
|
||||
---
|
||||
|
||||
A poll-based HTTP / HTTPS client for out-of-band data — leaderboards, cloud saves, remote config, telemetry, downloads. Open a request with <a href="http-get.html"><code>Http.get</code></a> / <a href="http-post.html"><code>Http.post</code></a> (or <a href="http-open.html"><code>Http.open</code></a> to add headers first), then each frame call <a href="http-poll.html"><code>Http.poll</code></a> — it returns <code>-1</code> while pending, <code>0</code> on error, or the status code — so the frame never blocks. Read the reply with <a href="http-status.html"><code>Http.status</code></a> / <a href="http-ok.html"><code>ok</code></a> / <a href="http-text.html"><code>text</code></a> / <a href="http-header.html"><code>header</code></a>, and pair it with <code>Json.*</code> for (de)serialization. TLS is the system's, on by default.
|
||||
A poll-based HTTP / HTTPS client for out-of-band data — leaderboards, cloud saves, remote config, telemetry, downloads. Open a request with <a href="http-get.html"><code>Http.get</code></a> / <a href="http-post.html"><code>Http.post</code></a> (or <a href="http-open.html"><code>Http.open</code></a> to add headers first), then each frame call <a href="http-poll.html"><code>Http.poll</code></a> — it returns <code>-1</code> while pending, <code>0</code> on error, or the status code — so the frame never blocks. Read the reply with <a href="http-status.html"><code>Http.status</code></a> / <a href="http-ok.html"><code>ok</code></a> / <a href="http-text.html"><code>text</code></a> / <a href="http-header.html"><code>header</code></a>, and pair it with <code>Json.*</code> for (de)serialization. TLS is the system's, on by default. A large download goes to a file instead of memory with <a href="http-save_to.html"><code>Http.save_to</code></a>, and <a href="http-received.html"><code>Http.received</code></a> / <a href="http-expected.html"><code>expected</code></a> drive a progress bar while it is pending.
|
||||
|
||||
HTTP depends on the network and the wall clock, so — like <code>Net.*</code> and <code>Time.now</code> — it is <strong>out-of-band</strong> and must never feed the deterministic lockstep/replay simulation. The transport is macOS-only for now; the raw-response parser (<a href="http-parse.html"><code>Http.parse</code></a>) is pure and portable.
|
||||
HTTP depends on the network and the wall clock, so — like <code>Net.*</code> and <code>Time.now</code> — it is <strong>out-of-band</strong> and must never feed the deterministic lockstep/replay simulation. The transport is NSURLConnection / NSURLSession on macOS and WinHTTP on Windows; the raw-response parser (<a href="http-parse.html"><code>Http.parse</code></a>) is pure and portable.
|
||||
|
|
|
|||
25
docs/language/http/http-expected.md
Normal file
25
docs/language/http/http-expected.md
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
---
|
||||
id: http-expected
|
||||
name: Http.expected
|
||||
category: http
|
||||
kind: namespace-method
|
||||
tokens: Http.expected
|
||||
sig: Http.expected(handle) -> int
|
||||
tip: The body length the server announced, or -1.
|
||||
order: 18
|
||||
ns: Http
|
||||
member: expected
|
||||
---
|
||||
|
||||
Returns the length of the response body as the server announced it (<code>Content-Length</code>), or <code>-1</code> while that is not known. For a request given <a href="http-save_to.html"><code>Http.save_to</code></a> it is known as soon as the headers arrive, and stays <code>-1</code> for a reply sent without a length (chunked) — draw an indeterminate bar then. For an ordinary in-memory request it is <code>-1</code> until the reply lands, then the body length.
|
||||
|
||||
```ludic
|
||||
program Demo {
|
||||
entry {
|
||||
let h = Http.open("GET", "https://example.com/big.bin")
|
||||
Http.save_to(h, "big.bin.part")
|
||||
Http.send(h)
|
||||
print(Http.expected(h)) # -1: nothing has arrived yet
|
||||
}
|
||||
}
|
||||
```
|
||||
25
docs/language/http/http-received.md
Normal file
25
docs/language/http/http-received.md
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
---
|
||||
id: http-received
|
||||
name: Http.received
|
||||
category: http
|
||||
kind: namespace-method
|
||||
tokens: Http.received
|
||||
sig: Http.received(handle) -> int
|
||||
tip: Body bytes received so far.
|
||||
order: 17
|
||||
ns: Http
|
||||
member: received
|
||||
---
|
||||
|
||||
Returns how many bytes of the response body have arrived. For a request given <a href="http-save_to.html"><code>Http.save_to</code></a> it is updated live while the request is pending — the bytes already written to the file — which is what a progress bar reads. For an ordinary in-memory request it is <code>0</code> until the reply lands, then the body length. <code>0</code> before <code>Http.send</code>.
|
||||
|
||||
```ludic
|
||||
program Demo {
|
||||
var dl: int = 0
|
||||
handler Bar phase Render {
|
||||
let got = Http.received(handle: dl)
|
||||
let all = Http.expected(handle: dl)
|
||||
if all > 0 { Screen.bar(x: 8, y: 8, width: 200, height: 6, value: got / 1024, max: all / 1024, color: 0x55cc77, back: 0x222222) }
|
||||
}
|
||||
}
|
||||
```
|
||||
28
docs/language/http/http-save_to.md
Normal file
28
docs/language/http/http-save_to.md
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
---
|
||||
id: http-save_to
|
||||
name: Http.save_to
|
||||
category: http
|
||||
kind: namespace-method
|
||||
tokens: Http.save_to
|
||||
sig: Http.save_to(handle, path) -> void
|
||||
tip: Stream the response body to a file.
|
||||
order: 16
|
||||
ns: Http
|
||||
member: save_to
|
||||
---
|
||||
|
||||
Makes the response body of an <a href="http-open.html"><code>Http.open</code></a>ed request go straight to the file at <code>path</code> as it arrives, instead of into memory — the way to download something large (an update package of hundreds of megabytes) with a progress bar. Call it before <a href="http-send.html"><code>Http.send</code></a>; afterwards it does nothing.
|
||||
|
||||
The file is written directly at <code>path</code>, with no temporary name: <code>Http.send</code> creates it (or truncates an existing one), and a failed or cancelled download leaves whatever had arrived. So download to a name of your own such as <code>"x.nupkg.part"</code> and rename it once <a href="http-poll.html"><code>Http.poll</code></a> reports a good status — a non-2xx reply's body (an error page) is written to the file too. If the file cannot be created the request finishes with status <code>0</code>, as does one whose write fails midway (a full disk).
|
||||
|
||||
For such a request <a href="http-text.html"><code>Http.text</code></a> is empty (<code>null</code>) and <a href="http-body_len.html"><code>Http.body_len</code></a> is the number of bytes written. Follow progress with <a href="http-received.html"><code>Http.received</code></a> and <a href="http-expected.html"><code>Http.expected</code></a>. Freeing the request while it is pending cancels the download. The transfer asks for no compression (<code>Accept-Encoding: identity</code>) unless the request set that header, so the bytes counted are the bytes on disk. Files are limited to 2 GB.
|
||||
|
||||
```ludic
|
||||
program Demo {
|
||||
entry {
|
||||
let h = Http.open("GET", "https://example.com/big.bin")
|
||||
Http.save_to(h, "big.bin.part")
|
||||
Http.send(h)
|
||||
}
|
||||
}
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue