This commit is contained in:
allexanderbergmns
2026-08-25 15:26:30 +02:00
parent 76e912c922
commit 4ccc8a0f95
16 changed files with 546 additions and 50 deletions
+18
View File
@@ -0,0 +1,18 @@
// json.vr — JSON helpers (part of the VuurRaaf stdlib).
//
// import json
// let data = json.decode("{\"a\": 1}")
// println(json.encode(data))
// println(json.pretty(data))
fn encode(x) {
return json_encode(x)
}
fn decode(s) {
return json_decode(s)
}
fn pretty(x) {
return json_pretty(x)
}
+61
View File
@@ -0,0 +1,61 @@
// math.vr — math helpers (part of the VuurRaaf stdlib).
//
// import math
// println(math.clamp(150, 0, 100))
// println(math.sign(-3))
fn abs(x) {
return abs(x)
}
fn min(a, b) {
return min(a, b)
}
fn max(a, b) {
return max(a, b)
}
fn floor(x) {
return floor(x)
}
fn ceil(x) {
return ceil(x)
}
fn round(x) {
return round(x)
}
fn sqrt(x) {
return sqrt(x)
}
fn pow(a, b) {
return pow(a, b)
}
fn clamp(x, lo, hi) {
if x < lo {
return lo
}
if x > hi {
return hi
}
return x
}
fn sign(x) {
if x < 0 {
return -1
}
if x > 0 {
return 1
}
return 0
}
fn pi() {
return 3.14159
}
+75
View File
@@ -0,0 +1,75 @@
// os.vr — operating system and filesystem helpers (part of the VuurRaaf stdlib).
//
// import os
// if os.exists("build.vrmm") {
// for f in os.list_dir(".") {
// println(f)
// }
// }
fn exists(path) {
return build_exists(path)
}
fn is_dir(path) {
return build_is_dir(path)
}
fn is_file(path) {
return build_exists(path) and not build_is_dir(path)
}
fn mkdir(path) {
build_mkdir(path)
return 0
}
fn remove(path) {
return build_rm(path)
}
fn copy(src, dst) {
build_copy(src, dst)
return 0
}
fn list_dir(path) {
return build_ls(path)
}
fn glob(pattern) {
return build_glob(pattern)
}
fn join(a, b) {
return build_join(a, b)
}
fn base(path) {
return build_base(path)
}
fn dir(path) {
return build_dir(path)
}
fn read_lines(path) {
return split_lines(read_file(path))
}
fn write_lines(path, lines) {
write_file(path, join(lines, "\n") + "\n")
return 0
}
fn cwd() {
return cwd()
}
fn env(name) {
return getenv(name)
}
fn exec(cmd) {
return build_exec(cmd)
}
+72
View File
@@ -0,0 +1,72 @@
// strings.vr — string helpers (part of the VuurRaaf stdlib).
//
// import strings
// println(strings.join(["a", "b"], ", "))
// println(strings.capitalize("hello"))
fn length(s) {
return len(s)
}
fn lines(s) {
return split_lines(s)
}
fn split(s, delim) {
return split(s, delim)
}
fn join(parts, delim) {
return join(parts, delim)
}
fn replace(s, from, to) {
return replace(s, from, to)
}
fn contains(s, sub) {
return contains(s, sub)
}
fn starts_with(s, prefix) {
return starts_with(s, prefix)
}
fn ends_with(s, suffix) {
return ends_with(s, suffix)
}
fn upper(s) {
return upper(s)
}
fn lower(s) {
return lower(s)
}
fn trim(s) {
return trim(s)
}
fn pad(s, width) {
return pad(s, width)
}
fn pad_left(s, width) {
return pad_left(s, width)
}
fn repeat(s, n) {
return repeat(s, n)
}
fn format(x, spec) {
return format(x, spec)
}
fn capitalize(s) {
if len(s) == 0 {
return s
}
return upper(s[0]) + s[1..]
}