[I see I was replying to Claude earlier. He says I shouldn't send proposed improvements to him alone, but to the list, in particular MrPeach, who maintains the distribution. So: ]
-- test receive support
local LReceive = pd.Class:new():register("lreceive")
function LReceive:initialize(name, atoms) if type(atoms[1]) ~= "string" then pd.post("lreceive needs a prefix for the receive names!") return false else self.prefix = atoms[1] end
[default is 'prefix1']* if type(atoms[2]) ~= "number" or atoms[2] < 1 then self.start = 1 else self.start = math.floor(atoms[2]) end
1.)* if type(atoms[3]) ~= "number" or atoms[3] < 1 then self.count = 1 else self.count = math.floor(atoms[3]) end self.receives = { } self.inlets = 0 self.outlets = 2 return true end
function LReceive:postinitialize() local i = 0 while (i < self.count) do local n = self.start + i self.receives[i+1] = pd.Receive:new():register(self, self.prefix .. n, "receive_" .. n) self["receive_" .. n] = function (self, sel, atoms) self:outlet(2, "float", { n }) self:outlet(1, sel, atoms) end i = i + 1 end end
function LReceive:finalize() for _,r in ipairs(self.receives) do r:destruct() end end
#N canvas 0 0 540 307 10; #X obj 27 41 lreceive lreceive- 25 10; #X obj 27 76 print lreceive-LEFT; #X obj 190 76 print lreceive-RIGHT; #X obj 26 252 send lreceive-25; #X msg 26 196 foo bar 1 2 3; #X msg 146 196 123 bar 1 2 3; #X obj 146 252 send lreceive-27; #X obj 272 252 send; #X floatatom 295 204 5 24 35 2 n - -; #X obj 295 226 makefilename lreceive-%d; #X symbolatom 272 171 10 0 0 0 - - -; #X obj 272 143 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; *#X text 100 10 This example receives messages sent to 'lreceive-25' and the next 9 addresses up to 'lreceive-34', ie 10 addresses;* #X connect 0 0 1 0; #X connect 0 1 2 0; #X connect 4 0 3 0; #X connect 5 0 6 0; #X connect 8 0 9 0; #X connect 9 0 7 1; #X connect 10 0 7 0; #X connect 11 0 10 0;
On Sat, Jul 4, 2015 at 10:07 AM, Claude Heiland-Allen claude@mathr.co.uk wrote:
Hi Forrest,
On 04/07/15 17:43, Forrest Curo wrote:
When I use the example lreceive.pd_lua to produce [lreceive poo], it won't receive.
Messages from [lsend poo] and [send poo] are both picked up by [r poo], but the lreceive just sits there.
Anyone have a guess what's going on?
[lreceive] actually binds a number of receives, named with a prefix. For example:
[lreceive poo 42 3]
is more like
[r poo42] [r poo43] [r poo44] | | | [t a b] [t a b] [t a b] | [42( | [43( | [44( | | | | | | (each pair is sent out from the 2 outlets of [lreceive])
The start (here 42) and count (here 3) both default to 1, so just to test that it's working try [s poo1].
Anyway, the examples I wrote weren't originally meant to be used as standalone objects (perhaps that was a mistake), but more as examples of how to use different parts of the pdlua API - you can read the source code of the .pd_lua examples (which are plain text) to guide you when writing your own objects, or just to see how they work.
Claude
Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list