Skip to content

Commit

Permalink
Integrate Ben's section on dollar symbol expansion, add example.
Browse files Browse the repository at this point in the history
  • Loading branch information
agraef committed Sep 23, 2024
1 parent ec139b5 commit fe4f9ed
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 57 deletions.
20 changes: 20 additions & 0 deletions pdlua/tutorial/examples/localsend.pd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#N canvas 580 203 398 197 12;
#X declare -lib pdlua;
#X obj 240 110 tgl 20 0 empty \$0-onoff empty 17 7 0 10 #dfdfdf #000000
#000000 1 1;
#X floatatom 240 144 5 0 0 0 - - -, f 5;
#X obj 40 120 bng 20 250 50 0 empty empty empty 17 7 0 10 #dfdfdf #000000
#000000;
#X text 68 119 <-- click me;
#X obj 175 19 declare -lib pdlua;
#X obj 40 154 localsend \$0-onoff;
#X obj 290 110 tgl 20 0 empty onoff empty 17 7 0 10 #dfdfdf #000000
#000000 0 1;
#X floatatom 290 144 5 0 0 0 - - -, f 5;
#X msg 40 50 sender \\\$0-onoff;
#X msg 40 80 sender onoff;
#X connect 0 0 1 0;
#X connect 2 0 5 0;
#X connect 6 0 7 0;
#X connect 8 0 5 0;
#X connect 9 0 5 0;
23 changes: 23 additions & 0 deletions pdlua/tutorial/examples/localsend.pd_lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
local localsend = pd.Class:new():register("localsend")

function localsend:initialize(sel, atoms)
self.inlets = 1
-- pass the symbol from the creation argument,
-- which gets automatically expanded here
self.sender = tostring(atoms[1])
return true
end

function localsend:in_1_sender(x)
local sendername = tostring(x[1])

-- store the original name as argument (like "\$0-foo")
self:set_args({sendername})

-- apply the expanded name with the local id
self.sender = self:canvas_realizedollar(sendername)
end

function localsend:in_1_bang()
pd.send(self.sender, "bang", {})
end
Binary file modified pdlua/tutorial/pd-lua-intro.pdf
Binary file not shown.
Binary file added tutorial/19-dollar-symbols.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit fe4f9ed

Please sign in to comment.