Skip to main content
Plugdata includes pd-lua, allowing you to create custom objects using Lua scripting. This provides a flexible way to extend plugdata without compiling C code.

Overview

Pd-lua enables:
  • ✅ Rapid prototyping of custom objects
  • ✅ No compilation required
  • ✅ Access to Pure Data’s messaging system
  • ✅ Signal processing capabilities
  • ✅ Dynamic inlet/outlet creation

Quick Start

Simple Message Object

Create a file named reverse.pd_lua:
reverse.pd_lua
Use in a patch:

The [lua] Object

Plugdata includes a special [lua] object for inline Lua code:

[lua] Object Syntax

Options:
  • -in <n> - Number of data inlets
  • -out <n> - Number of data outlets
  • -sigin <n> - Number of signal inlets
  • -sigout <n> - Number of signal outlets
Code:
  • Separate from options with ;
  • Use ; as newline separator
  • Escape commas in function arguments with \,

Inline Code Examples

The [lua] object source code: Resources/Patches/lua.pd_lua:1-155

Creating .pd_lua Files

Basic Structure

myobject.pd_lua

Inlet/Outlet Configuration

Message Handlers

Naming Convention

  • <inlet>: Inlet number (1-based)
  • <selector>: Message type (bang, float, symbol, list, etc.)

Standard Selectors

Multiple Inlets

Sending Messages

Output Methods

Atoms Table

Atoms must be passed as a table, even for single values:
  • ✅ {3.14}
  • ❌ 3.14

Signal Processing

DSP Setup

Signal Buffer Access

Advanced Features

Creation Arguments

Usage: [myobject 880 square]

Clock (Timing)

Table Access

Sending to Named Receivers

Utility Functions

Complete Example: Random Sequencer

randomseq.pd_lua

Loading Lua Externals

Place .pd_lua files in:
  • Same directory as your patch
  • ~/Documents/plugdata/externals/
  • Any path in Pd’s search paths
Or use the [lua] object’s load message:

Debugging Tips

Limitations

  • GUI objects require C/C++ implementation
  • Performance-critical DSP better in C
  • Limited access to internal Pd structures
  • No direct access to audio hardware

Resources

  • pd-lua API implementation: Source/Pd/Setup.cpp:1317-1321, 1399-1408
  • [lua] object source: Resources/Patches/lua.pd_lua
  • Example externals in Libraries/pd-lua/ directory

Next Steps

Adding Externals

Compile C externals into plugdata

Performance Optimization

Optimize your patches