Function Description Example print(...)Print values to console print("Hello", x, y);input(prompt)Read string from user str name = input("Name: ");inputInt(prompt)Read integer int age = inputInt("Age: ");inputFloat(prompt)Read float float val = inputFloat("Value: ");
Function Description Example toInt(value)Convert to integer int x = toInt("123");toFloat(value)Convert to float float y = toFloat("3.14");toString(value)Convert to string str s = toString(42);toBool(value)Convert to boolean bool b = toBool(1);
Function Description Example length(arr)Get array/object length int len = length(arr);push(arr, value)Add element push(arr, 10);pop(arr)Remove and return last int x = pop(arr);range(n)Create integer range for (i in range(10)) {...}keys(obj)Get object keys (insertion order) array k = keys({a:1,b:2});
Function Description Example now_iso8601()Current UTC time as ISO 8601 str now = now_iso8601();format_iso8601(secs)Unix seconds → YYYY-MM-DDTHH:MM:SSZ str s = format_iso8601(0);parse_iso8601(s)ISO 8601 → unix seconds (-1 on fail) int t = parse_iso8601(now);weekday(secs)Day of week (0=Sun … 6=Sat) int d = weekday(timestamp());date_add_seconds(t, d)Add d seconds to t int t2 = date_add_seconds(t, 3600);timestamp()Current Unix epoch (seconds) int now = timestamp();time_ms()Current Unix epoch (milliseconds) int ms = time_ms();clock_ms()Monotonic high-precision timer float t = clock_ms();sleep(ms)Sleep for ms milliseconds sleep(100);
POSIX/ECMAScript syntax via std::regex.
Function Description Example regex_match(pat, s)1 if s fully matches pat int ok = regex_match("[0-9]+", "42");regex_search(pat, s)1 if substring of s matches int hit = regex_search("\\d+", "x42y");regex_capture(pat, s)[whole, g1, g2, ...] or []array g = regex_capture("(\\w+)=(\\w+)", "a=b");regex_replace(pat, s, r)Replace all matches; $1 etc str s = regex_replace("\\d", "x", "_");
Function Description Example read_file(path)Read whole file str s = read_file("data.txt");write_file(path, data)Truncate + write write_file("out.txt", body);append_file(path, data)Append to existing append_file("log.txt", line);file_exists(path)Check existence bool ok = file_exists("x");file_glob(pattern)Shell-style * ? glob array f = file_glob("./*.tpr");
Built on an in-tree SHA-256 — no OpenSSL dependency, available everywhere
the runtime runs.
Function Description Example sha256(s)Lowercase 64-char hex digest str h = sha256(body);hmac_sha256(key, msg)Keyed MAC (RFC 2104), 64-char hex str sig = hmac_sha256(secret, data);password_hash(pw)PBKDF2-HMAC-SHA256, self-describing str h = password_hash(pw);password_verify(pw, stored)Constant-time check vs password_hash bool ok = password_verify(pw, h);secure_token(n)CSPRNG base62 string, n chars str t = secure_token(48);base64_encode(s) / base64_decode(s)Standard base64 (byte-safe) str b = base64_encode(raw);
Guidance:
Passwords → password_hash / password_verify. Never store bare
sha256(pw) (unsalted, fast to brute-force).
Session / API tokens, salts → secure_token, not randint
(which is not cryptographically secure).
Signing / authentication (signed cookies, webhook signatures,
JWT-style tokens) → hmac_sha256 with a long random secret. Verify by
recomputing the MAC and comparing.
hmac_sha256 is what the wings_jwt
package uses to issue and verify HS256 session tokens:
import " wings_jwt " as jwt;
str token = jwt. sign_ttl ({ " sub " : " 42 " , " role " : " admin " }, SECRET, 3600 );
json v = jwt. verify (token, SECRET); // {"ok":1,"claims":{…}} | {"ok":0,"error":…}
Function Description Example csv_parse(s)RFC 4180 → array of rows array rows = csv_parse(text);csv_emit(rows)Array of rows → CSV string str s = csv_emit(rows);
Function Description Example env(name)Read env var (empty if unset) str dbg = env("DEBUG");exit(code)Terminate with status exit(1);
Function Description Example arena_save()Snapshot current arena tip int wm = arena_save();arena_restore(wm)Roll back allocs to that tip arena_restore(wm);
Wings auto-uses these per request so long-running servers don’t grow
memory. Handlers MUST NOT stash arena pointers on globals.
Function Description Example thread_create(fn, arg)Spawn thread; returns thread id int t = thread_create(worker, x);thread_join(id)Wait for thread to finish thread_join(t);thread_detach(id)Detach (auto-cleanup on exit) thread_detach(t);mutex_create()Create a mutex int m = mutex_create();mutex_lock(m)Acquire lock mutex_lock(m);mutex_unlock(m)Release lock mutex_unlock(m);mutex_destroy(m)Free a mutex mutex_destroy(m);
http_* builtins are documented separately in
HTTP Server (Wings) and
HTTP Client .