Disting NT Lua scripts run at control resolution (not audio rate). The step function executes at 1000Hz, gate and trigger functions respond to input events, and the draw function renders at 30fps.
Current hardware has 64 logical buses: 12 input, 8 output, and 44 aux. Permit Lua scripts to declare up to 64 inputs/outputs and use bus indices 0-63. The v1.17 Lua booklet's older 0-28 wording is stale; use the v1.17 user manual's signal-flow architecture as the current truth surface.
<quick_start> Basic LFO script generating square and triangle waves:
return {
name = 'LFO',
author = 'Expert Sleepers Ltd',
init = function(self)
self.t = 0.0
return {
inputs = 1,
outputs = { kStepped, kLinear }
}
end,
step = function(self, dt, inputs)
local f = 1 + inputs[1]
self.t = (self.t + dt * f) % 1.0
local sqr = self.t > 0.5 and 5.0 or -5.0
local tri = 20 * math.min(self.t, 1 - self.t) - 5
return { sqr, tri }
end
}
The `step` function runs at 1000Hz. Input 1 modulates frequency. Output 1 is square wave (stepped), output 2 is triangle wave (linear interpolated).
All scripts must return a table with:
- `name` and `author` fields
- `init(self)` function that returns configuration
- `step(self, dt, inputs)` function that returns output voltages
Optional callbacks: `trigger`, `gate`, `draw`, `ui`, `serialise`, `midiMessage`
Critical callback distinction:
- Lua Script algorithm and custom-algorithm UI callbacks receive `self` first.
- Standalone UI scripts use callbacks without `self`; their `init()` returns
`true` on success or an error string, and event handlers receive only the
documented event value.
</quick_start>
<reference_guides>
**Complete API reference**: [reference.md](reference.md) - Firmware v1.17 callbacks, parameters, drawing API, discovery, MIDI/I2C, serialization, and compatibility checks
**Working examples**: [examples.md](examples.md) - LFO, ADSR, shift register, and bouncy ball implementations
**Algorithm template**: [templates/template.lua](templates/template.lua) - Annotated Lua Script algorithm template
**Standalone UI template**: [templates/ui-script.lua](templates/ui-script.lua) - Correct no-`self` UI script signatures
</reference_guides>
<success_criteria>
Script successfully:
- Loads without Lua syntax errors
- Processes inputs at 1000Hz via step/trigger/gate callbacks
- Returns correct voltage ranges (typically -10V to +10V)
- Draws custom UI at 30fps if draw() implemented
- Serializes state correctly if serialise() implemented
- Uses pre-allocated tables to avoid garbage collection during step()
- Handles MIDI messages correctly if midiMessage() implemented
- Preserves unchanged outputs when returning sparse output tables
- Uses integer coordinates for integer drawing primitives and floating-point
coordinates only for `drawSmoothLine`/`drawSmoothCircle`
- Uses the correct callback signature for algorithm versus standalone UI scripts
</success_criteria>