Package index
OSL ships its standard library as importable packages:
import "std:fs"
log fs.readFile("notes.txt")An import adds a package value with the same name. For example, std:fs adds fs. Use the std: prefix in new code. The older osl/ spelling still works, but the compiler reports a migration warning.
How imports work
import "std:fs"
A standard-library package listed below
import "./helpers.osl"
A local OSL file, relative to the importing file
import "utils" or import "./utils"
Every .osl file directly inside a local directory
import "git.rotur.dev/me/tools"
A Git dependency installed by Opal
import "go:net/http"
A Go package
Directory imports sort files by name and do not recurse. Import or re-export child directories yourself.
Missing third-party Go dependencies are fetched automatically when you compile.
Module objects
The statement form merges another file's declarations into the current scope. Its top-level statements run once, where OSL first imports the file. The expression form returns its public API as an object instead:
object math = import("./math.osl")
log math.add(2, 3)
log math.square(4)Without an export statement, a file exposes all of its declarations. Adding an export statement turns on an explicit public API for that file:
Consumers can import the full API, selected names, or a namespace:
Files in the same directory can share private declarations. Consumers in another directory see only exported declarations. Missing, duplicate, and conflicting exports are compile errors.
Here math.square and math.quadruple are callable from outside. import(...) works with local .osl files whose path is a string literal.
Returned objects
Some packages give you an object to keep working with. For example, db.open() returns a database handle, and you call further methods on that:
Each package page lists handle methods in a separate section.
The standard library at a glance
Web & networking
HTTP server / web framework (routing, middleware, contexts).
WebSocket client and server.
Bot framework for OriginChats servers.
HTTP client methods including get, post, and put.
Low-level TCP/UDP sockets and DNS lookups.
URL parsing, building and query-string handling.
FTP file transfers.
SSH connections, remote commands and SCP.
S3-compatible object storage client.
Web Push notifications (VAPID).
Data & serialization
JSON parsing and encoding.
YAML parsing and encoding.
Composable validation and normalization schemas.
CSV parsing plus a small dataframe-style toolkit.
XML parsing and querying.
Lightweight {{ }} templating with HTML escaping.
Markdown to HTML (CommonMark + GFM via goldmark).
MIME-type lookup and parsing.
Text/line/word diffing.
Databases & storage
Filesystem & system
Crypto & security
Text, math & time
Emoji detection, extraction, replacement, flags, and skin tones.
Regular expressions plus validators and text helpers.
Semantic-version parsing and comparison.
Maths, statistics and number theory.
Seedable pseudo-random numbers.
Dates, durations and time zones.
Cron-style job scheduling.
Bounded retries with exponential backoff and jitter.
Terminal & logging
Media & documents
Graphics & windowing
GLSL and OSL-style shader transpilation and rendering to images and windows.
Native windowing, input, 2D drawing, collision helpers, shaders, and textures.
Open a window and draw to it (the originOS graphics model).
Install native window controls.
Scripting & concurrency
Utilities & data structures
More
To read a package's source directly from the CLI:
Last updated