Skip to content

System

Module name: "io". Can be disabled for sandboxed scripts.

FunctionSignatureDescription
readFile(path: string) -> stringRead file contents
writeFile(path: string, content: string)Write to file
readLine() -> stringRead line from stdin
fileExists(path: string) -> boolCheck if file exists
let content = readFile("data/config.writ")
writeFile("output/log.txt", "Game started")
let line = readLine()
let exists = fileExists("saves/slot1.dat")

Module name: "time".

FunctionSignatureDescription
now() -> floatCurrent timestamp (seconds)
elapsed(start: float) -> floatSeconds since start
let start = now()
// ... do work ...
let elapsed = elapsed(start) // seconds since start

Module name: "random". Backed by the rand crate.

FunctionSignatureDescription
random() -> floatFloat in 0.0..1.0
randomInt(min: int, max: int) -> intInt in min..=max
randomFloat(min: float, max: float) -> floatFloat in range
shuffle(arr: Array<T>)Shuffle array in place
random() // float in 0.0..1.0
randomInt(1, 6) // int in 1..=6 (inclusive)
randomFloat(0.0, 100.0) // float in range
shuffle(myArray) // shuffles array in place

Module name: "regex". Backed by the regex crate.

MethodSignatureDescription
test(input: string) -> boolDoes pattern match?
match(input: string) -> Optional<string>First match
matchAll(input: string) -> Array<string>All matches
replace(input: string, rep: string) -> stringReplace first occurrence
replaceAll(input: string, rep: string) -> stringReplace all occurrences
let re = Regex("\\d+")
re.test("abc123") // true
re.match("abc123") // Optional<string> — first match
re.matchAll("a1b2c3") // Array<string> — all matches
re.replace("a1b2", "X") // "aXb2"
re.replaceAll("a1b2", "X") // "aXbX"