From 267170167d52cab9e97f879d9127a1cf04f6bb58 Mon Sep 17 00:00:00 2001 From: Martin Peach Date: Tue, 15 Mar 2011 20:53:57 +0000 Subject: This is a version of Claude Heiland-Allen's lua for Pd. The objects are named pdlua and pdluax instead of lua and luax. So far it seems to work on linux. svn path=/trunk/externals/pdlua/; revision=15030 --- examples/lreceive.pd_lua | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 examples/lreceive.pd_lua (limited to 'examples/lreceive.pd_lua') diff --git a/examples/lreceive.pd_lua b/examples/lreceive.pd_lua new file mode 100644 index 0000000..e75beda --- /dev/null +++ b/examples/lreceive.pd_lua @@ -0,0 +1,44 @@ +-- 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 + if type(atoms[2]) ~= "number" or atoms[2] < 1 then + self.start = 1 + else + self.start = math.floor(atoms[2]) + end + 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 + -- cgit v1.2.1