diff options
| author | s-ol <s+removethis@s-ol.nu> | 2025-08-05 01:44:00 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-08-05 01:44:22 +0000 |
| commit | 8ab97cc7144c02d96d2bd382d36c56ac30f28e06 (patch) | |
| tree | bc152a2e705cfaeb8965803f16acb28c2d6c6915 | |
| parent | lib/osc: send bangs as I(mpulse) (diff) | |
| download | alive-8ab97cc7144c02d96d2bd382d36c56ac30f28e06.tar.gz alive-8ab97cc7144c02d96d2bd382d36c56ac30f28e06.zip | |
builtins: add doto macro
| -rw-r--r-- | alv/builtins.moon | 32 | ||||
| -rw-r--r-- | examples/glsl-view/stream-controls.alv | 21 |
2 files changed, 53 insertions, 0 deletions
diff --git a/alv/builtins.moon b/alv/builtins.moon index 7640ac8..84978f1 100644 --- a/alv/builtins.moon +++ b/alv/builtins.moon @@ -753,6 +753,37 @@ is always inserted as the last argument." value: mk_thread '->>', false +doto = Constant.meta + meta: + name: 'doto' + summary: "Pass argument to multiple functions." + examples: { '(doto initial [expr1 expr2…])' } + description: " +Insert the result of the `initial` expression to all other expressions `expr1`, `expr2`, … +The value is always inserted as the first argument. + +Returns the result of the `initial` expression." + + value: class extends Builtin + eval: (scope, tail) => + L\trace "evaling #{@}" + assert #tail > 1, "'#{name}' requires at least 2 arguments" + + value = L\push tail[1]\eval, scope + + children = for cell in *tail[2,] + assert cell.__class == Cell, "'#{name}'s arguments have to be expressions" + + args = [c for c in *cell.children] + table.insert args, 2, Dummy value\make_ref! + + cell = Cell cell.tag, args + cell\eval scope + + table.insert children, value + + super RTNode :children, result: value.result + Constant.meta meta: summary: "builtin operators and constants." @@ -782,6 +813,7 @@ Constant.meta '->': thread_first '->>': thread_last + :doto :mkarray, :mkstruct :fmt diff --git a/examples/glsl-view/stream-controls.alv b/examples/glsl-view/stream-controls.alv new file mode 100644 index 0000000..fb37c31 --- /dev/null +++ b/examples/glsl-view/stream-controls.alv @@ -0,0 +1,21 @@ +([1]import* glsl-view link-time) +([2]import osc) + +([3]def + *clock* ([8]clock false 120) + *oscout* ([5]osc/connect 'localhost' 9000)) + +([6]def + paused? ([12]switch ([13]every 2) true false) + cam ([16]doto ([7]stream-source 'webcam' '2D' '/dev/video0') + ([11]freeze paused?) + ([14]step! ([15]every 0.5)))) + +([9]draw $[10]shader" +in vec2 uv; +out vec4 color; + +void main() { + color = texture($cam , uv); + color.rgb = mix(color.rgb, color.rrr, $paused? ? 1 : 0); +}") |
