Standard Library Reference
xxc Standard Library & Operator Reference
> Every module ships inside the single-file distribution — nothing to
> install. Sections marked *(async; concurrency)* participate in the async
> I/O runtime under --features concurrency; db/sqlite needs the
> sqlite feature. Related pages:
> Language Guide ·
> 中文版:标准库与运算符参考。
Standard Library
std/time
time.now() ms since epoch
time.epoch() seconds since epoch
time.sleep(ms) block the current thread *(not task-aware)*
std/json
json.encode(v) -> string (structs/classes/arrays/maps)
json.decode(s) -> value (objects become indexable)
std/random
rand.int(max) [0, max)
rand.float() [0, 1)
rand.seed(n)
rand.choice(arr)
rand.shuffle(arr) -> new shuffled array
std/os
os.file_exists(path) -> bool
os.read_file(path) -> string
os.write_file(path, content)
os.mkdir(path)
os.list_dir(path) -> array of names
os.env(key) -> string or nil
os.cwd() -> string
std/regex
re.matches(pat, text) -> bool
re.find(pat, text) -> first match string or nil
re.find_all(pat, text) -> array of all matches
re.replace(pat, text, repl) -> string
re.split(pat, text) -> array
Supported syntax: literals, ., * + ? {n,m}, character classes
[abc] [^abc] [a-z], \d \w \s (and negations), ^ $ anchors, |,
(...), escapes.
std/crypto
crypto.md5(s) -> 32-hex-char digest
crypto.sha256(s) -> 64-hex-char digest
std/base64
b64.encode(s) b64.decode(s)
std/uri
u := uri.parse("https://host:8080/path?q=1")
u.scheme u.host u.port u.path u.query
uri.encode(s) percent-encoding
std/fs *(async; concurrency)*
fs.read_file(path) fs.write_file(path, content)
net/tcp *(async; concurrency)*
l := tcp.listen(port)
c := tcp.accept(l)
line := tcp.read_line(c) // up to and including '\n'
body := tcp.read(c, n) // exactly n bytes
tcp.write(c, s)
tcp.close(c)
net/http *(async; concurrency)*
body := http.get("http://host/path")
db/sqlite *(feature sqlite)*
db := sqlite.open(path) // ":memory:" works
sqlite.exec(db, sql) // DDL / DML
rows := sqlite.query(db, sql) // -> array of row objects
sqlite.close(db)
for row in rows { print(row.id, row.name) }
gui (headless)
root := gui.col([gui.text("Hi"), gui.rect(60, 20, gui.rgb(40,120,200))])
gui.render(root, "out.svg", w, h)
gui.render_bmp(root, "out.bmp", w, h)
gui.row([...]) gui.text(s) gui.rect(w,h,color) gui.rgb(r,g,b)
gui.show(root, w, h) // native window (feature gui-window)
js — built-in JavaScript engine
js.run(code) // execute, print via console.log
js.eval(code) // execute, return last value (converted)
The engine implements an ES subset: let/const, functions + arrows, objects,
arrays, closures, control flow, try/catch, Math, JSON, console.
webview
wv.render(html, w, h, "out.bmp") // parse + lay out + rasterize
wv.run_scripts(html) // execute <script> tags
Operators
Precedence (highest to lowest):
| Prec | Operators | Category |
|---|---|---|
| highest | fn(...) call, . field/index, [...] index, postfix ? | postfix |
| — | unary - ! ~ | unary |
| 7 | * / % | multiplicative |
| 6 | + - | additive |
| 5 | << >> & \| ^ | bitwise |
| 4 | < <= > >= | comparison |
| 3 | == != | equality |
| 2 | && | and |
| 1 | \|\| | or |
| 0 | = (assignment), ch <- v (send) | assignment |
&&/|| short-circuit. + adds numbers and concatenates strings
(string + non-string is a type error; convert with str()). Bitwise ops
work on int (& | ^ also on bool). Integer division truncates;
x / 0 and x % 0 on ints are runtime errors.