Standard Library
StarLang ships with a set of built-in libraries implemented as native C modules. Import them with import and call functions with the module prefix.
Available Libraries
| Library | Description |
|---|---|
| math | Mathematical functions — trigonometry, rounding, power, logarithms |
| time | Time and date — timestamps, component extraction, formatting |
| json | JSON parsing and serialization — parse, stringify, helpers |
| queue | In-memory ring buffer queue — configurable overflow, batch pop, stats |
| crypto | SHA-256/512 hashing, HMAC, UUID v4, random bytes |
| net | TCP/UDP sockets — connect, listen, send, recv |
| http | HTTP/1.1 client — GET, POST, PUT, DELETE, custom headers |
| ws | WebSocket client — connect, send, recv, ping/pong, auto-reconnect |
| config | Read-only typed config — host-injected key-value access |
| mqtt | MQTT 3.1.1 client — publish, subscribe, receive, auto-reconnect |
| wifi | Station-mode WiFi — connect, lifecycle events, link status (ESP32 radio / PC shim) |
star.mod
To use a library, add a require line to your project's star.mod manifest:
import "math" then resolves to that path and math.sqrt(x) compiles to an OP_NATIVE_CALL. See the star.mod reference for every directive (module, star, require, config) and how paths resolve.
How Libraries Work
Standard libraries are native C modules (dev-libs/<name>/<name>.c). Each library exposes an init function:
void star_mod_math_init(StarVM *vm) {
star_vm_register_native(vm, "math", "sqrt", native_sqrt);
star_vm_register_native(vm, "math", "abs", native_abs);
// ...
}
The CLI reads star.mod, matches library names, and calls the corresponding init function. The compiler resolves math.sqrt(x) to an OP_NATIVE_CALL opcode with a function index — zero overhead at runtime.
Each library is platform-aware. On PC, all libraries are available. On ESP32, only libraries that fit the target's capabilities are included (e.g., no filesystem on bare metal).
Planned Libraries
| Library | Description | Status |
|---|---|---|
math |
Math functions | Available |
time |
Time and date | Available |
json |
JSON parse/stringify | Available |
queue |
Ring buffer queue | Available |
crypto |
Hashing, HMAC, UUID | Available |
string |
String utilities | Planned |
fs |
File system (PC only) | Won't add |
net |
TCP/UDP sockets | Available |
http |
HTTP client | Available |
ws |
WebSocket client | Available |
config |
Read-only typed config | Available |
mqtt |
MQTT 3.1.1 client | Available |
wifi |
Station-mode WiFi (ESP32 / PC shim) | Available |
settings |
Writable persistent settings | Planned |