1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
local luarecv = pd.Class:new():register("luarecv")
function luarecv:initialize(sel, atoms)
self.inlets = 1
self.outlets = 1
-- pass the receiver symbol as creation argument
local sym = tostring(atoms[1])
pd.post(string.format("luarecv: receiver '%s'", sym))
-- create the receiver
self.recv = pd.Receive:new():register(self, sym, "receive")
return true
end
function luarecv:finalize()
self.recv:destruct()
end
function luarecv:receive(sel, atoms)
-- simply store the message, so that we can output it later
self.sel, self.atoms = sel, atoms
pd.post(string.format("luarecv: got '%s %s'", sel,
table.concat(atoms, " ")))
end
function luarecv:in_1_bang()
-- output the last message we received (if any)
if self.sel then
self:outlet(1, self.sel, self.atoms)
end
end
|