Lua
Run Lua once per frame over four numeric inputs and return four numeric outputs.
What it does
Runs a snippet of Lua once per frame and turns its result into up to four numeric outputs. The code defines one function, execute(inputs, ctx), which reads the node's four number inputs and returns a table of outputs (out_0 … out_3). It is built for small, fast per-frame logic: arithmetic, conditionals, oscillators, state machines, rather than heavy processing.
Each Lua node keeps its own private script state, so copies of the same subgraph do not leak variables into each other.
When to use it
Logic a single Expression node cannot express cleanly: loops, branches, small helper functions.
Combining several numbers under custom rules (blend, remap, step through cases) to drive other nodes.
Prototyping behaviour in a lightweight scripting sandbox instead of building it from primitive nodes.
| Parameter | Type | Default |
|---|---|---|
code | String | "function execute(inputs, ct..." |
in_0 | Number | — |
in_1 | Number | — |
in_2 | Number | — |
in_3 | Number | — |
Gotchas
The Code field can be wired from an upstream node, a text or template node for example, instead of typed in directly. Scripts can then be generated or swapped from elsewhere in the graph.
The code must define a global function execute(inputs, ctx) ... end that returns a table. If execute is missing, or the return value is not a table with the expected keys, the corresponding outputs stay at their default.
The node always has exactly four inputs (in_0–in_3) and four outputs (out_0–out_3). There is no way to add a fifth. An unwired input arrives as 0 inside inputs.
Worked example
Add a Lua node. The default code doubles
in_0and returns it asout_0. Run it once to see the pattern.Wire numbers into
in_0–in_3, then edit the code to combine them, e.g.return { out_0 = inputs.in_0 + inputs.in_1 }.Return more of
out_0–out_3from the sameexecutecall to drive several downstream nodes from one script.
See also
p5.js · Script · Attribute Wrangle · Numbers, signals & audio