Skip to content

Built-in Functions

FunctionDescriptionExample
print(...)Print values to consoleprint("Hello", x, y);
input(prompt)Read string from userstr name = input("Name: ");
inputInt(prompt)Read integerint age = inputInt("Age: ");
inputFloat(prompt)Read floatfloat val = inputFloat("Value: ");
FunctionDescriptionExample
toInt(value)Convert to integerint x = toInt("123");
toFloat(value)Convert to floatfloat y = toFloat("3.14");
toString(value)Convert to stringstr s = toString(42);
toBool(value)Convert to booleanbool b = toBool(1);
FunctionDescriptionExample
length(arr)Get array/object lengthint len = length(arr);
push(arr, value)Add elementpush(arr, 10);
pop(arr)Remove and return lastint x = pop(arr);
range(n)Create integer rangefor (i in range(10)) {...}
keys(obj)Get object keys (insertion order)array k = keys({a:1,b:2});
FunctionDescriptionExample
now_iso8601()Current UTC time as ISO 8601str now = now_iso8601();
format_iso8601(secs)Unix seconds → YYYY-MM-DDTHH:MM:SSZstr 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 tint 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 timerfloat t = clock_ms();
sleep(ms)Sleep for ms millisecondssleep(100);

POSIX/ECMAScript syntax via std::regex.

FunctionDescriptionExample
regex_match(pat, s)1 if s fully matches patint ok = regex_match("[0-9]+", "42");
regex_search(pat, s)1 if substring of s matchesint 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 etcstr s = regex_replace("\\d", "x", "_");
FunctionDescriptionExample
read_file(path)Read whole filestr s = read_file("data.txt");
write_file(path, data)Truncate + writewrite_file("out.txt", body);
append_file(path, data)Append to existingappend_file("log.txt", line);
file_exists(path)Check existencebool ok = file_exists("x");
file_glob(pattern)Shell-style * ? globarray f = file_glob("./*.tpr");
FunctionDescriptionExample
csv_parse(s)RFC 4180 → array of rowsarray rows = csv_parse(text);
csv_emit(rows)Array of rows → CSV stringstr s = csv_emit(rows);
FunctionDescriptionExample
env(name)Read env var (empty if unset)str dbg = env("DEBUG");
exit(code)Terminate with statusexit(1);
FunctionDescriptionExample
arena_save()Snapshot current arena tipint wm = arena_save();
arena_restore(wm)Roll back allocs to that tiparena_restore(wm);

Wings auto-uses these per request so long-running servers don’t grow memory. Handlers MUST NOT stash arena pointers on globals.

FunctionDescriptionExample
thread_create(fn, arg)Spawn thread; returns thread idint t = thread_create(worker, x);
thread_join(id)Wait for thread to finishthread_join(t);
thread_detach(id)Detach (auto-cleanup on exit)thread_detach(t);
mutex_create()Create a mutexint m = mutex_create();
mutex_lock(m)Acquire lockmutex_lock(m);
mutex_unlock(m)Release lockmutex_unlock(m);
mutex_destroy(m)Free a mutexmutex_destroy(m);

http_* builtins are documented separately in HTTP Server (Wings) and HTTP Client.