A window in a browser tab: (Web open title w h scale) listens for a page, and Sdl’s other messages draw to it, play sound on it, and read its keys and gamepads.
WebA window in a browser tab: Sdl’s messages answered by a page that shows an RGBA picture on a canvas, plays signed 16-bit sound through Web Audio, and sends keys and gamepad input back over a WebSocket.
open listens on 127.0.0.1, ports 8080 to 8089 then any the kernel gives, unless listen! names others, and prints the page’s address on stderr.
%window-cellStatic field: data held by Web itself, not by its instances.
%listen-cellStatic field: data held by Web itself, not by its instances.
%stream-countStatic field: data held by Web itself, not by its instances.
%guidStatic field: data held by Web itself, not by its instances.
%pageStatic field: data held by Web itself, not by its instances.
(Web listen! host ports)Name where the next open listens.
Parameters:
STRING — Dotted-quad address to listen on: 127.0.0.1 for this machine only, 0.0.0.0 for every interface, as in a containerINTEGER|LIST — The port, or the candidates to try in order, as Socket tcp-listen-on takes themReturns: STRING — The host
Examples:
(Web listen! "127.0.0.1" 8080) => "127.0.0.1"(Web available?)Whether a Web window can be opened: always, as it needs nothing outside x.
Returns: BOOL — #t
Examples:
(Web available?) => #t(Web keys)Keycodes by name for keys that are not printable characters: Sdl’s, as the page sends SDL’s keycodes.
Returns: LIST — ((name . keycode) …)
Examples:
(first (Web keys)) => ('up . 1073741906)(Web key name)The keycode the page sends for a named key.
Parameters:
SYMBOL — A key name from (Web keys)Returns: INTEGER — SDL’s keycode
Examples:
(Web key (lit escape)) => 27(Web buttons)Gamepad button names, as Sdl’s: the page maps a standard gamepad’s buttons to them.
Returns: LIST — Button names
Examples:
(first (Web buttons)) => 'south(Web axes)Gamepad axis names, as Sdl’s.
Returns: LIST — Axis names
Examples:
(first (Web axes)) => 'left-x(Web error)The last error message: always empty, as Web raises its errors.
Returns: STRING — “”
Examples:
(Web error) => ""(Web %ref win field)A field of the window.
Parameters:
VECTOR — A window from openSYMBOL — A field nameReturns: ANY — Its value
(Web %set! win field v)Set a field of the window.
Parameters:
VECTOR — A window from openSYMBOL — A field nameANY — The new valueReturns: ANY — v
(Web %field field)The slot that holds a field of the window.
Parameters:
SYMBOL — A field nameReturns: INTEGER — The slot
Examples:
(Web %field (lit page)) => 1(Web %window)The window open, or nil.
Returns: ANY — The window
(Web open title w h scale)Listen for a browser and keep a w x h RGBA picture for it, scaled by whole multiples with nearest-pixel sampling. Prints the page’s address on stderr; frames drawn before a page connects are kept, and the last is sent when one does.
Parameters:
STRING — The page’s titleINTEGER — Picture width in pixelsINTEGER — Picture height in pixelsINTEGER — Taken for Sdl’s sake: the page fits the picture to the tabReturns: VECTOR — The window
(Web url win)The address of the window’s page.
Parameters:
VECTOR — A window from openReturns: STRING — An http URL
(Web %serve! win)Take any new connection and read whatever the page has sent, without waiting.
Parameters:
VECTOR — A window from openReturns: ANY — nil
(Web %connect! win fd)Answer one HTTP request on fd: the page, the WebSocket the page opens, or not found.
Parameters:
VECTOR — A window from openINTEGER — A connection just acceptedReturns: ANY — nil
(Web %request fd)An HTTP request’s head, read until its blank line or 16 KB.
Parameters:
INTEGER — A connectionReturns: STRING — The request head
(Web %respond fd status type body)Send one HTTP response and its body.
Parameters:
INTEGER — A connectionSTRING — Status line’s code and wordsSTRING — Content-TypeSTRING — The body, textReturns: ANY — nil
(Web %header name request lower)A request header’s value, or nil.
Parameters:
STRING — A header name, lower case, with its colonSTRING — The request headSTRING — The request head, lower caseReturns: ANY — The value, trimmed
(Web accept-key key)The Sec-WebSocket-Accept answer to a WebSocket key (RFC 6455): the base64 of the SHA-1 of the key and the protocol’s GUID.
Parameters:
STRING — A Sec-WebSocket-Key header’s valueReturns: STRING — The answer
Examples:
(Web accept-key "dGhlIHNhbXBsZSBub25jZQ==") => "s3pPLMBiTxaQ9kYGzzhZRbK+xOo="(Web %upgrade! win fd request lower)Make fd the page’s WebSocket, in place of any before it, and send it the window’s state.
Parameters:
VECTOR — A window from openINTEGER — A connectionSTRING — Its request headSTRING — The head, lower caseReturns: ANY — nil
(Web %drop! win)Forget the page’s socket, closing it.
Parameters:
VECTOR — A window from openReturns: ANY — nil
(Web %send! win op head head-n body body-n)Send one frame to the page, if there is one; a page that has gone is dropped.
Parameters:
VECTOR — A window from openINTEGER — The opcode: 1 text, 2 binary, 8 closeSTRING — The payload’s first bytesINTEGER — How manyANY — The rest of the payload, or nilINTEGER — How many bytes of bodyReturns: ANY — nil
(Web %put-be! p at v n)Write v as n big-endian bytes.
Parameters:
POINTER — WhereINTEGER — OffsetINTEGER — ValueINTEGER — BytesReturns: ANY — nil
(Web %tell! win text)Send the page a text message.
Parameters:
VECTOR — A window from openSTRING — A message: a word and its argumentsReturns: ANY — nil
(Web %read! win)Read what the page has sent and queue its events; a page that has closed is dropped.
Parameters:
VECTOR — A window from openReturns: ANY — nil
(Web %frames! win bytes)Take each whole frame from bytes, queue the events of its text, and keep the rest.
Parameters:
VECTOR — A window from openLIST — Bytes read and not yet whole framesReturns: ANY — nil
(Web %get-be bytes n)The first n bytes read as a big-endian number.
Parameters:
LIST — BytesINTEGER — How manyReturns: INTEGER — The number
Examples:
(Web %get-be (list 1 44) 2) => 300(Web %unmask bytes mask)The payload with the mask taken off: each byte exclusive-or the mask’s byte at its place, four round.
Parameters:
LIST — A payloadLIST — Four mask bytes, or nilReturns: LIST — The bytes
Examples:
(Web %unmask (list 3 1) (list 1 2 3 4)) => (2 3)(Web %event bytes)The event a message names: its first word a symbol, each other word a number when it reads as one and a symbol when not.
Parameters:
LIST — A text message’s bytes: an event’s wordsReturns: LIST — The event
Examples:
(Web %event (list 112 97 100 45 117 112 32 115 111 117 116 104 32 48)) => ('pad-up 'south 0)(Web %text bytes)A string of the bytes.
Parameters:
LIST — Byte valuesReturns: STRING — The string
Examples:
(Web %text (list 104 105)) => "hi"(Web %queue! win event)Put an event at the end of the queue poll answers from.
Parameters:
VECTOR — A window from openLIST — An eventReturns: ANY — nil
(Web scaling! win mode)Set how the page scales the picture to the tab: by whole multiples, or as large as fits.
Parameters:
VECTOR — A window from openSYMBOL — whole: whole multiples only; fit: as large as the tab allows, its shape keptReturns: VECTOR — The window
(Web canvas win)A zeroed RGBA buffer the size of the window’s picture: transparent black.
Parameters:
VECTOR — A window from openReturns: STRING — A region of wh4 bytes
(Web draw! win buf)Keep the buffer as the frame; nothing is sent until present!.
Parameters:
VECTOR — A window from openSTRING — An RGBA buffer the window’s sizeReturns: VECTOR — The window
(Web present! win)Send the frame drawn last to the page.
Parameters:
VECTOR — A window from openReturns: VECTOR — The window
(Web show! win buf)Draw the buffer and send it.
Parameters:
VECTOR — A window from openSTRING — An RGBA buffer the window’s sizeReturns: VECTOR — The window
(Web read-pixels win)The frame drawn last, as an RGBA buffer; nil before any.
Parameters:
VECTOR — A window from openReturns: ANY — A region of wh4 bytes, or nil
(Web fullscreen! win on)Ask the page to fill the screen, or to leave it; a browser grants it only after a key or a click.
Parameters:
VECTOR — A window from openBOOL — #t for fullscreen, #f for a windowReturns: VECTOR — The window
(Web poll)The next event from the page, or nil; the same events as Sdl’s poll answers.
Returns: ANY — An event list, or nil
(Web post-key! code)Queue a key-down event, as a key pressed on the page would be.
Parameters:
INTEGER — An SDL keycodeReturns: INTEGER — The code
(Web close win)Tell the page the window is closed and close the sockets.
Parameters:
VECTOR — A window from openReturns: ANY — nil
(Web %now)The wall clock in microseconds.
Returns: INTEGER — Microseconds since the epoch
(Web %opened s)The message that opens a stream on the page.
Parameters:
VECTOR — A streamReturns: STRING — The message
(Web %rate s)The stream’s bytes a second.
Parameters:
VECTOR — A streamReturns: INTEGER — Bytes a second
(Web audio-open rate chans)Open a stream of signed 16-bit frames to the page; nothing is heard until a key or a click has started the page’s sound.
Parameters:
INTEGER — Frames a second, such as 44100INTEGER — Channels: 1 or 2Returns: VECTOR — The stream
(Web audio-put! s buf n)Send n bytes of buf to play after what the stream has.
Parameters:
VECTOR — A stream from audio-openSTRING — Samples, signed 16-bit little-endian, channels interleavedINTEGER — How many bytes of bufReturns: VECTOR — The stream
(Web audio-queued s)Bytes sent to the stream and not yet played, by the clock.
Parameters:
VECTOR — A stream from audio-openReturns: INTEGER — Bytes
(Web audio-clear! s)Drop what the stream has not played.
Parameters:
VECTOR — A stream from audio-openReturns: VECTOR — The stream
(Web audio-close s)Release the stream.
Parameters:
VECTOR — A stream from audio-openReturns: ANY — nil