Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Standard Library

Beyond the core built-ins (Input & Output, string conversions), Lumen ships a small standard library covering strings, files, randomness, and HTTP.

Capabilities

File I/O, random, and HTTP are optional features that a given VM build may or may not implement. See Capabilities for assertCapability and how to check for them.

File I/O

Requires the FS capability.

FunctionDescription
openFile path, &handleOpen a file, storing a handle in handle
writeFile data, handleWrite a string to an open file
readFile &out, handleRead the full contents of an open file into out
closeFile handleClose an open file handle

Random

Requires the random capability.

FunctionDescription
randomSeed seedSeed the random number generator
random &outGenerate a random float in [0.0, 1.0) into out
randomRange min, max, &outGenerate a random integer in [min, max] (inclusive) into out

HTTP

Requires the HTTP capability.

FunctionDescription
httpRequest method, url, headers, body, &status, &responsePerform an HTTP request
  • method'GET', 'POST', 'PUT', or 'DELETE' (case-insensitive)
  • url — full URL including scheme, e.g. 'http://example.com/path'
  • headers — newline-separated Key: Value pairs, or '' for none
  • body — request body string, ignored for GET
  • status — receives the HTTP status code, or -1 on a connection-level failure
  • response — receives the response body, or an error message on failure

HTTPS URLs are not currently supported — only plain http:// requests.

String Manipulation

See Strings for strlen, substr, strfind, strcase, and trim.