RADS Logo

๐Ÿ“š Standard Library

Complete reference for built-in modules and functions

Built-in Functions

FunctionDescriptionExample
echo(value)Print to stdoutecho("Hello")
to_string(value)Convert to stringto_string(42)
to_int(value)Convert to integerto_int("123")
to_float(value)Convert to floatto_float("3.14")

Module: net

Networking and HTTP functionality.

Functions

  • http_server(host, port) - Create HTTP server
  • route(server, path, handler) - Register route
  • static(server, prefix, dir) - Serve static files
  • serve(server) - Start server
  • http_get(url) - HTTP GET request
  • http_post(url, body) - HTTP POST request
  • json_response(json) - Create JSON response

Module: io

File I/O and stream processing.

Functions

  • read_file(path) - Read entire file
  • write_file(path, content) - Write to file
  • open(path, mode) - Open file stream
  • close(stream) - Close stream
  • read_line(stream) - Read line from stream

Module: media

Audio and image processing.

Functions

  • load_audio(path) - Load audio file
  • load_image(path) - Load image file
  • convert(output, format, bitrate) - Convert audio
  • resize(width, height) - Resize image
  • apply_filter(name) - Apply image filter

Module: string

String manipulation and inspection (30 functions).

Manipulation

  • str.length(str) - Get string length
  • str.upper(str) - Convert to uppercase
  • str.lower(str) - Convert to lowercase
  • str.trim(str) - Remove whitespace
  • str.substring(str, start, length) - Extract substring
  • str.replace(str, search, replace) - Replace all occurrences
  • str.repeat(str, count) - Repeat string
  • str.reverse(str) - Reverse string
  • str.title(str) - Title case string
  • str.capitalize(str) - Capitalize first character
  • str.split(str, delim) - Split into array
  • str.join(arr) - Join array into string
  • str.pad_left(str, width) - Left-pad string
  • str.pad_right(str, width) - Right-pad string
  • str.ljust(str, width) - Left-justify in width
  • str.rjust(str, width) - Right-justify in width
  • str.center(str, width) - Center in width

Inspection

  • str.contains(str, sub) - Check if contains substring
  • str.starts_with(str, prefix) - Check prefix
  • str.ends_with(str, suffix) - Check suffix
  • str.is_empty(str) - Check if empty
  • str.isdigit(str) - Check if all digits
  • str.isalpha(str) - Check if all letters
  • str.isalnum(str) - Check if alphanumeric
  • str.char_at(str, index) - Get character at index
  • str.find(str, sub) - Find first occurrence index
  • str.rfind(str, sub) - Find last occurrence index
  • str.count(str, sub) - Count occurrences

Conversion

  • str.to_int(str) - Parse as integer
  • str.to_float(str) - Parse as float

Module: datetime ๐Ÿ•

Date and time handling for real-world applications.

Functions

FunctionDescriptionExample
datetime.now()Current timestamp as structdatetime.now().year
datetime.format(ts, fmt)Format timestamp to stringdatetime.format(now, "YYYY-MM-DD")
datetime.parse(str, fmt)Parse string to timestampdatetime.parse("2025-03-01", "YYYY-MM-DD")
datetime.unix(ts)Get Unix timestampdatetime.unix(now)
datetime.from_unix(unix)Create from Unix timestampdatetime.from_unix(1772373508)
datetime.add(ts, days, hrs, min, sec)Add time to timestampdatetime.add(now, 1)
datetime.diff(ts1, ts2)Time difference in secondsdatetime.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

FunctionDescriptionExample
regex.compile(pattern)Compile regex pattern (cached)regex.compile("\\d+")
regex.match(regex, str)Boolean match checkregex.match(p, "123")
regex.findall(regex, str)Find all matchesregex.findall(p, "a1b2")
regex.search(regex, str)First match with positionregex.search(p, "price: 99")
regex.replace(regex, str, repl)Replace matchesregex.replace(p, "a1", "X")
regex.split(regex, str)Split by patternregex.split(p, "a,b;c")
regex.groups(regex, str)Extract capture groupsregex.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

FunctionDescription
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

FunctionDescriptionExample
env.get(name)Get environment variableenv.get("HOME")
env.set(name, value)Set environment variableenv.set("DEBUG", "1")
env.has(name)Check if variable existsenv.has("PATH")
env.unset(name)Remove environment variableenv.unset("DEBUG")
env.list()Get all variables as structenv.list()
env.paths()Parse PATH into arrayenv.paths()
env.home()Get HOME directoryenv.home()
env.cwd()Get current working directoryenv.cwd()
env.user()Get current usernameenv.user()
env.shell()Get current shellenv.shell()

Module: cli ๐Ÿ–ฅ๏ธ

Command-line argument parsing for CLI tools.

Functions

FunctionDescriptionExample
cli.args()Get raw argument arraycli.args()
cli.program()Get program namecli.program()
cli.count()Get argument countcli.count()
cli.has_flag(name)Check if flag presentcli.has_flag("--verbose")
cli.flag(name)Get flag valuecli.flag("--output")
cli.flags()Get all flags as structcli.flags()
cli.args_after_flag(name)Get args after flagcli.args_after_flag("--")
cli.parse(spec)Parse with specificationcli.parse(spec)

Module: csv ๐Ÿ“Š

CSV file parsing and generation for data processing.

Functions

FunctionDescriptionExample
csv.parse(str)Parse CSV string to arraycsv.parse(data)
csv.stringify(data)Convert array to CSV stringcsv.stringify(rows)
csv.read(path)Read CSV filecsv.read("data.csv")
csv.write(path, data)Write CSV filecsv.write("out.csv", rows)

Module: time โฑ๏ธ

High-precision timing and sleep functions with nanosecond precision.

Functions

FunctionDescriptionExample
time.sleep(seconds)Sleep for specified secondstime.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 epochtime.millis()
time.micros()Microseconds since epochtime.micros()
time.perf_counter()High-resolution timer for benchmarkstime.perf_counter()
time.monotonic()Monotonic clock (never goes backwards)time.monotonic()
time.clock()Process CPU timetime.clock()
time.process_time()Process + system CPU timetime.process_time()
time.thread_time()Current thread CPU timetime.thread_time()

Module: random ๐ŸŽฒ

Random number generation with multiple distributions.

Functions

FunctionDescriptionExample
random.seed(value)Seed the RNGrandom.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 arrayrandom.choice([1,2,3])
random.shuffle(array)Shuffle array in placerandom.shuffle(arr)
random.sample(array, n)Random sample of n elementsrandom.sample(arr, 3)
random.bool()Random booleanrandom.bool()
random.uuid()Generate UUID v4 stringrandom.uuid()

Module: path ๐Ÿ“

Cross-platform path manipulation and filesystem operations.

Functions

FunctionDescriptionExample
path.join(...parts)Join path parts with OS separatorpath.join("a", "b", "c")
path.basename(path)Get filename from pathpath.basename("/a/b/c.txt")
path.dirname(path)Get directory from pathpath.dirname("/a/b/c.txt")
path.extname(path)Get file extensionpath.extname("file.txt")
path.stem(path)Get filename without extensionpath.stem("file.txt")
path.is_absolute(path)Check if path is absolutepath.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.sepOS path separatorpath.sep
path.cwd()Current working directorypath.cwd()
path.home()User home directorypath.home()
path.glob(pattern)Find files matching patternpath.glob("*.rads")

Module: os ๐Ÿ–ฅ๏ธ

System introspection and process control.

Functions

FunctionDescriptionExample
os.name()OS name (linux, darwin, windows)os.name()
os.version()OS version stringos.version()
os.arch()CPU architecture (x64, arm64)os.arch()
os.hostname()System hostnameos.hostname()
os.info()Full system info structos.info()
os.pid()Current process IDos.pid()
os.ppid()Parent process IDos.ppid()
os.uid()Current user IDos.uid()
os.gid()Current group IDos.gid()
os.exit(code)Exit process with codeos.exit(0)
os.env()Get all env vars as structos.env()
os.setenv(name, value)Set environment variableos.setenv("DEBUG", "1")
os.unsetenv(name)Remove environment variableos.unsetenv("DEBUG")
os.cpu_count()Number of CPU coresos.cpu_count()
os.pagesize()System memory page sizeos.pagesize()
os.mem_total()Total system memory (bytes)os.mem_total()
os.mem_available()Available memory (bytes)os.mem_available()
os.cwd()Current working directoryos.cwd()
os.tmpdir()System temporary directoryos.tmpdir()
os.sleep(ms)Sleep for millisecondsos.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 infinity
  • math.NAN() - Not-a-Number

Basic Operations

  • math.abs(x) - Absolute value
  • math.min(a, b) - Minimum of two values
  • math.max(a, b) - Maximum of two values
  • math.sign(x) - Sign (-1, 0, 1)
  • math.clamp(x, min, max) - Clamp to range
  • math.lerp(a, b, t) - Linear interpolation

Rounding

  • math.floor(x) - Round down
  • math.ceil(x) - Round up
  • math.round(x) - Round to nearest
  • math.trunc(x) - Truncate toward zero

Powers & Roots

  • math.sqrt(x) - Square root
  • math.cbrt(x) - Cube root
  • math.pow(x, y) - x raised to power y
  • math.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/x
  • math.deg_to_rad(deg) - Degrees to radians
  • math.rad_to_deg(rad) - Radians to degrees

Hyperbolic

  • math.sinh(x), math.cosh(x), math.tanh(x)

Logarithmic & Exponential

  • math.exp(x) - e^x
  • math.log(x) - Natural logarithm
  • math.log2(x) - Base-2 logarithm
  • math.log10(x) - Base-10 logarithm

Special Value Checks

  • math.isnan(x) - Check for NaN
  • math.isinf(x) - Check for infinity
  • math.isfinite(x) - Check for finite number

Array Operations

  • math.sum(arr) - Sum of array
  • math.avg(arr) - Average of array
  • math.median(arr) - Median of array

Module: base64 ๐Ÿ”

Base64 encoding and decoding for data encoding.

Functions

FunctionDescriptionExample
base64.encode(str)Encode string to base64base64.encode("hello")
base64.decode(str)Decode base64 to stringbase64.decode("aGVsbG8=")
base64.encode_bytes(arr)Encode byte arraybase64.encode_bytes(bytes)
base64.decode_bytes(str)Decode to byte arraybase64.decode_bytes(enc)

Other Built-ins

FunctionDescription web_init()Initialize web engine js_eval(code)Execute JavaScript js_evalFile(path)Run JS file html_parse(html)Parse HTML html_querySelector(doc, selector)Query DOM css_parse(css)Parse CSS pkg_load(name)Load plugin pkg_list()List plugins