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_0out_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

ParameterTypeDefault
codeString"function execute(inputs, ct..."
in_0Number
in_1Number
in_2Number
in_3Number

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_0in_3) and four outputs (out_0out_3). There is no way to add a fifth. An unwired input arrives as 0 inside inputs.

Worked example

  1. Add a Lua node. The default code doubles in_0 and returns it as out_0. Run it once to see the pattern.

  2. Wire numbers into in_0in_3, then edit the code to combine them, e.g. return { out_0 = inputs.in_0 + inputs.in_1 }.

  3. Return more of out_0out_3 from the same execute call to drive several downstream nodes from one script.

See also

p5.js · Script · Attribute Wrangle · Numbers, signals & audio