Skip to content

Commit

Permalink
Added shortcuts for classes, arrays, clocks, and receivers.
Browse files Browse the repository at this point in the history
These can now all be created and registered in a single call:

pd.class(name)
pd.table(name)
pd.clock(obj, method)
pd.receive(obj, sym, method)

Much less to write, much easier to remember. It's such a simple thing,
yet it reduces cognitive load and improves usability quite a lot.

Of course, you can still use the whole pd.Class:new():register(...) and
pd.Table:new():sync(...), etc. rigmarole if you prefer, in fact the
shortcuts are implemented in terms of these. They're simple (tail)
calls, so overhead is negligible.
  • Loading branch information
agraef committed Sep 7, 2024
1 parent eead672 commit 63a8f50
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions pd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,31 @@ function luax:initialize(sel, atoms) -- motivation: pd-list 2007-09-23
end
end

-- convenience creation functions for classes, arrays, clocks, receivers

function pd.class(...)
return pd.Class:new():register(...)
end

function pd.table(...)
return pd.Table:new():sync(...)
end

function pd.clock(...)
return pd.Clock:new():register(...)
end

function pd.receive(...)
return pd.Receive:new():register(...)
end

-- constants used in the signal and graphics API
DATA = 0
SIGNAL = 1
Colors = {background = 0, foreground = 1, outline = 2}

-- pre-load pdx.lua (live coding support); if you don't want this, just
-- comment out the line below
-- pre-load pdx.lua (advanced live coding support); if you don't want this,
-- just comment out the line below
pdx = require 'pdx'

-- fin pd.lua

0 comments on commit 63a8f50

Please sign in to comment.