๐ Standard Library
Complete reference for built-in modules and functions
Built-in Functions
| Function | Description | Example |
|---|---|---|
echo(value) | Print to stdout | echo("Hello") |
to_string(value) | Convert to string | to_string(42) |
to_int(value) | Convert to integer | to_int("123") |
to_float(value) | Convert to float | to_float("3.14") |
Module: net
Networking and HTTP functionality.
Functions
http_server(host, port)- Create HTTP serverroute(server, path, handler)- Register routestatic(server, prefix, dir)- Serve static filesserve(server)- Start serverhttp_get(url)- HTTP GET requesthttp_post(url, body)- HTTP POST requestjson_response(json)- Create JSON response
Module: io
File I/O and stream processing.
Functions
read_file(path)- Read entire filewrite_file(path, content)- Write to fileopen(path, mode)- Open file streamclose(stream)- Close streamread_line(stream)- Read line from stream
Module: media
Audio and image processing.
Functions
load_audio(path)- Load audio fileload_image(path)- Load image fileconvert(output, format, bitrate)- Convert audioresize(width, height)- Resize imageapply_filter(name)- Apply image filter
Module: string
String manipulation and inspection (30 functions).
Manipulation
str.length(str)- Get string lengthstr.upper(str)- Convert to uppercasestr.lower(str)- Convert to lowercasestr.trim(str)- Remove whitespacestr.substring(str, start, length)- Extract substringstr.replace(str, search, replace)- Replace all occurrencesstr.repeat(str, count)- Repeat stringstr.reverse(str)- Reverse stringstr.title(str)- Title case stringstr.capitalize(str)- Capitalize first characterstr.split(str, delim)- Split into arraystr.join(arr)- Join array into stringstr.pad_left(str, width)- Left-pad stringstr.pad_right(str, width)- Right-pad stringstr.ljust(str, width)- Left-justify in widthstr.rjust(str, width)- Right-justify in widthstr.center(str, width)- Center in width
Inspection
str.contains(str, sub)- Check if contains substringstr.starts_with(str, prefix)- Check prefixstr.ends_with(str, suffix)- Check suffixstr.is_empty(str)- Check if emptystr.isdigit(str)- Check if all digitsstr.isalpha(str)- Check if all lettersstr.isalnum(str)- Check if alphanumericstr.char_at(str, index)- Get character at indexstr.find(str, sub)- Find first occurrence indexstr.rfind(str, sub)- Find last occurrence indexstr.count(str, sub)- Count occurrences
Conversion
str.to_int(str)- Parse as integerstr.to_float(str)- Parse as float
Module: datetime ๐
Date and time handling for real-world applications.
Functions
| Function | Description | Example |
|---|---|---|
datetime.now() | Current timestamp as struct | datetime.now().year |
datetime.format(ts, fmt) | Format timestamp to string | datetime.format(now, "YYYY-MM-DD") |
datetime.parse(str, fmt) | Parse string to timestamp | datetime.parse("2025-03-01", "YYYY-MM-DD") |
datetime.unix(ts) | Get Unix timestamp | datetime.unix(now) |
datetime.from_unix(unix) | Create from Unix timestamp | datetime.from_unix(1772373508) |
datetime.add(ts, days, hrs, min, sec) | Add time to timestamp | datetime.add(now, 1) |
datetime.diff(ts1, ts2) | Time difference in seconds | datetime.diff(tomorrow, now) |
datetime.weekday(ts) | Day of week (0=Sunday) | datetime.weekday(now) |
Timestamp Struct Fields
.year- Year (2025).month- Month (1-12).day- Day (1-31).hour- Hour (0-23).minute- Minute (0-59).second- Second (0-59).unix- Unix timestamp
Module: regex ๐
Pattern matching and text manipulation using POSIX regex.
Functions
| Function | Description | Example |
|---|---|---|
regex.compile(pattern) | Compile regex pattern (cached) | regex.compile("\\d+") |
regex.match(regex, str) | Boolean match check | regex.match(p, "123") |
regex.findall(regex, str) | Find all matches | regex.findall(p, "a1b2") |
regex.search(regex, str) | First match with position | regex.search(p, "price: 99") |
regex.replace(regex, str, repl) | Replace matches | regex.replace(p, "a1", "X") |
regex.split(regex, str) | Split by pattern | regex.split(p, "a,b;c") |
regex.groups(regex, str) | Extract capture groups | regex.groups("(\\d+)", "abc123") |
Module: test ๐งช
Built-in testing framework with familiar assertions.
Test Structure
import test;
test.describe("My tests", blast() {
test.it("should work", blast() {
test.expect(1 + 1).toBe(2);
});
});
test.run();
Assertion Functions
| Function | Description |
|---|---|
test.describe(name, fn) | Define test suite |
test.it(name, fn) | Define test case |
test.expect(val).toBe(expected) | Strict equality |
test.expect(val).toEqual(expected) | Deep equality |
test.expect(val).toBeTruthy() | Truthy check |
test.expect(val).toBeFalsy() | Falsy check |
test.expect(val).toBeNull() | Null check |
test.expect(val).toBeGreaterThan(n) | Greater than |
test.expect(val).toBeLessThan(n) | Less than |
test.beforeEach(fn) | Setup before each test |
test.afterEach(fn) | Cleanup after each test |
test.run() | Execute all tests |
test.skip(name, fn) | Skip a test |
Module: env ๐
Environment variable access and system information.
Functions
| Function | Description | Example |
|---|---|---|
env.get(name) | Get environment variable | env.get("HOME") |
env.set(name, value) | Set environment variable | env.set("DEBUG", "1") |
env.has(name) | Check if variable exists | env.has("PATH") |
env.unset(name) | Remove environment variable | env.unset("DEBUG") |
env.list() | Get all variables as struct | env.list() |
env.paths() | Parse PATH into array | env.paths() |
env.home() | Get HOME directory | env.home() |
env.cwd() | Get current working directory | env.cwd() |
env.user() | Get current username | env.user() |
env.shell() | Get current shell | env.shell() |
Module: cli ๐ฅ๏ธ
Command-line argument parsing for CLI tools.
Functions
| Function | Description | Example |
|---|---|---|
cli.args() | Get raw argument array | cli.args() |
cli.program() | Get program name | cli.program() |
cli.count() | Get argument count | cli.count() |
cli.has_flag(name) | Check if flag present | cli.has_flag("--verbose") |
cli.flag(name) | Get flag value | cli.flag("--output") |
cli.flags() | Get all flags as struct | cli.flags() |
cli.args_after_flag(name) | Get args after flag | cli.args_after_flag("--") |
cli.parse(spec) | Parse with specification | cli.parse(spec) |
Module: csv ๐
CSV file parsing and generation for data processing.
Functions
| Function | Description | Example |
|---|---|---|
csv.parse(str) | Parse CSV string to array | csv.parse(data) |
csv.stringify(data) | Convert array to CSV string | csv.stringify(rows) |
csv.read(path) | Read CSV file | csv.read("data.csv") |
csv.write(path, data) | Write CSV file | csv.write("out.csv", rows) |
Module: time โฑ๏ธ
High-precision timing and sleep functions with nanosecond precision.
Functions
| Function | Description | Example |
|---|---|---|
time.sleep(seconds) | Sleep for specified seconds | time.sleep(1.5) |
time.time() | Current time as float (seconds since epoch) | time.time() |
time.unix() | Current Unix timestamp (integer seconds) | time.unix() |
time.millis() | Milliseconds since epoch | time.millis() |
time.micros() | Microseconds since epoch | time.micros() |
time.perf_counter() | High-resolution timer for benchmarks | time.perf_counter() |
time.monotonic() | Monotonic clock (never goes backwards) | time.monotonic() |
time.clock() | Process CPU time | time.clock() |
time.process_time() | Process + system CPU time | time.process_time() |
time.thread_time() | Current thread CPU time | time.thread_time() |
Module: random ๐ฒ
Random number generation with multiple distributions.
Functions
| Function | Description | Example |
|---|---|---|
random.seed(value) | Seed the RNG | random.seed(42) |
random.int() | Random integer (platform-dependent range) | random.int() |
random.float() | Random float [0.0, 1.0) | random.float() |
random.range(min, max) | Random integer in [min, max] | random.range(1, 100) |
random.choice(array) | Random element from array | random.choice([1,2,3]) |
random.shuffle(array) | Shuffle array in place | random.shuffle(arr) |
random.sample(array, n) | Random sample of n elements | random.sample(arr, 3) |
random.bool() | Random boolean | random.bool() |
random.uuid() | Generate UUID v4 string | random.uuid() |
Module: path ๐
Cross-platform path manipulation and filesystem operations.
Functions
| Function | Description | Example |
|---|---|---|
path.join(...parts) | Join path parts with OS separator | path.join("a", "b", "c") |
path.basename(path) | Get filename from path | path.basename("/a/b/c.txt") |
path.dirname(path) | Get directory from path | path.dirname("/a/b/c.txt") |
path.extname(path) | Get file extension | path.extname("file.txt") |
path.stem(path) | Get filename without extension | path.stem("file.txt") |
path.is_absolute(path) | Check if path is absolute | path.is_absolute("/a/b") |
path.normalize(path) | Normalize path (resolve . and ..) | path.normalize("a/b/../c") |
path.split(path) | Split into (dir, name) | path.split("/a/b/c") |
path.splitext(path) | Split into (name, ext) | path.splitext("file.txt") |
path.sep | OS path separator | path.sep |
path.cwd() | Current working directory | path.cwd() |
path.home() | User home directory | path.home() |
path.glob(pattern) | Find files matching pattern | path.glob("*.rads") |
Module: os ๐ฅ๏ธ
System introspection and process control.
Functions
| Function | Description | Example |
|---|---|---|
os.name() | OS name (linux, darwin, windows) | os.name() |
os.version() | OS version string | os.version() |
os.arch() | CPU architecture (x64, arm64) | os.arch() |
os.hostname() | System hostname | os.hostname() |
os.info() | Full system info struct | os.info() |
os.pid() | Current process ID | os.pid() |
os.ppid() | Parent process ID | os.ppid() |
os.uid() | Current user ID | os.uid() |
os.gid() | Current group ID | os.gid() |
os.exit(code) | Exit process with code | os.exit(0) |
os.env() | Get all env vars as struct | os.env() |
os.setenv(name, value) | Set environment variable | os.setenv("DEBUG", "1") |
os.unsetenv(name) | Remove environment variable | os.unsetenv("DEBUG") |
os.cpu_count() | Number of CPU cores | os.cpu_count() |
os.pagesize() | System memory page size | os.pagesize() |
os.mem_total() | Total system memory (bytes) | os.mem_total() |
os.mem_available() | Available memory (bytes) | os.mem_available() |
os.cwd() | Current working directory | os.cwd() |
os.tmpdir() | System temporary directory | os.tmpdir() |
os.sleep(ms) | Sleep for milliseconds | os.sleep(1000) |
Module: math โ
Comprehensive mathematical functions (40+ functions). Covers trigonometry, hyperbolic, logarithmic, and utility operations.
Constants
math.PI()- ฯ (3.141592653589793)math.E()- e (2.718281828459045)math.INF()- Positive infinitymath.NAN()- Not-a-Number
Basic Operations
math.abs(x)- Absolute valuemath.min(a, b)- Minimum of two valuesmath.max(a, b)- Maximum of two valuesmath.sign(x)- Sign (-1, 0, 1)math.clamp(x, min, max)- Clamp to rangemath.lerp(a, b, t)- Linear interpolation
Rounding
math.floor(x)- Round downmath.ceil(x)- Round upmath.round(x)- Round to nearestmath.trunc(x)- Truncate toward zero
Powers & Roots
math.sqrt(x)- Square rootmath.cbrt(x)- Cube rootmath.pow(x, y)- x raised to power ymath.hypot(a, b)- Hypotenuse
Trigonometric (radians)
math.sin(x),math.cos(x),math.tan(x)math.asin(x),math.acos(x),math.atan(x)math.atan2(y, x)- Arc tangent of y/xmath.deg_to_rad(deg)- Degrees to radiansmath.rad_to_deg(rad)- Radians to degrees
Hyperbolic
math.sinh(x),math.cosh(x),math.tanh(x)
Logarithmic & Exponential
math.exp(x)- e^xmath.log(x)- Natural logarithmmath.log2(x)- Base-2 logarithmmath.log10(x)- Base-10 logarithm
Special Value Checks
math.isnan(x)- Check for NaNmath.isinf(x)- Check for infinitymath.isfinite(x)- Check for finite number
Array Operations
math.sum(arr)- Sum of arraymath.avg(arr)- Average of arraymath.median(arr)- Median of array
Module: base64 ๐
Base64 encoding and decoding for data encoding.
Functions
| Function | Description | Example |
|---|---|---|
base64.encode(str) | Encode string to base64 | base64.encode("hello") |
base64.decode(str) | Decode base64 to string | base64.decode("aGVsbG8=") |
base64.encode_bytes(arr) | Encode byte array | base64.encode_bytes(bytes) |
base64.decode_bytes(str) | Decode to byte array | base64.decode_bytes(enc) |
Other Built-ins
web_init()js_eval(code)js_evalFile(path)html_parse(html)html_querySelector(doc, selector)css_parse(css)pkg_load(name)pkg_list()