diff options
author | Martin Peach <mrpeach@users.sourceforge.net> | 2011-03-15 20:53:57 +0000 |
---|---|---|
committer | Martin Peach <mrpeach@users.sourceforge.net> | 2011-03-15 20:53:57 +0000 |
commit | 267170167d52cab9e97f879d9127a1cf04f6bb58 (patch) | |
tree | 00260a90ce6472e34c5eff41602af57595c8830d /examples/lreceive.pd_lua |
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.svn2git-root
svn path=/trunk/externals/pdlua/; revision=15030
Diffstat (limited to 'examples/lreceive.pd_lua')
-rw-r--r-- | examples/lreceive.pd_lua | 44 |
1 files changed, 44 insertions, 0 deletions
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 + |