Array: len, push, pop, filter, map, concat, contains, reverse, slice, indexOf, find, some, every, flat, sort (mutating ops re-trigger signal) Math: abs, min, max, floor, ceil, round, random, sqrt, pow, sin, cos, tan, atan2, clamp, lerp String: split, join, trim, upper, lower, replace, starts_with, ends_with, char_at, substring Conversion: int, float, string, bool Console: log, debug, warn Timer: delay Also adds ExprStatement support for top-level expressions (log, push, etc). 110 tests, 0 failures.
43 lines
1,015 B
Text
43 lines
1,015 B
Text
-- DreamStack built-in functions test
|
|
-- Tests array, math, string, and conversion builtins
|
|
|
|
let items = [1, 2, 3, 4, 5]
|
|
let name = "DreamStack"
|
|
|
|
-- Array operations
|
|
let count = len(items)
|
|
let has_three = contains(items, 3)
|
|
|
|
-- Math operations
|
|
let x = floor(3.7)
|
|
let y = ceil(2.1)
|
|
let small = min(10, 5)
|
|
let big = max(10, 5)
|
|
let clamped = clamp(15, 0, 10)
|
|
let dist = sqrt(pow(3, 2) + pow(4, 2))
|
|
|
|
-- String operations
|
|
let upper_name = upper(name)
|
|
let lower_name = lower(name)
|
|
|
|
-- Console
|
|
log("count:", count)
|
|
log("distance:", dist)
|
|
|
|
view main =
|
|
column [
|
|
text "Built-in Functions"
|
|
text "Items: {count}"
|
|
text "Has 3: {has_three}"
|
|
text "floor(3.7) = {x}"
|
|
text "ceil(2.1) = {y}"
|
|
text "min(10,5) = {small}"
|
|
text "max(10,5) = {big}"
|
|
text "clamp(15,0,10) = {clamped}"
|
|
text "sqrt(3²+4²) = {dist}"
|
|
text "upper = {upper_name}"
|
|
text "lower = {lower_name}"
|
|
button "Push 6" { click: push(items, 6) }
|
|
button "Pop" { click: pop(items) }
|
|
text "Length: {len(items)}"
|
|
]
|