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/ldemux.pd_lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 examples/ldemux.pd_lua (limited to 'examples/ldemux.pd_lua') diff --git a/examples/ldemux.pd_lua b/examples/ldemux.pd_lua new file mode 100644 index 0000000..2c4301f --- /dev/null +++ b/examples/ldemux.pd_lua @@ -0,0 +1,28 @@ +-- contributed by Frank Barknecht + +local LDemux = pd.Class:new():register("ldemux") + +function LDemux:initialize(name, atoms) + local n = atoms[1] or 2 -- default to 2 outlets. + if type(n) ~= "number" or n < 2 then + pd.post("ldemux: wrong outlet-count argument, using 2 outlets instead") + n = 2 + end + self.outlets = n + self.inlets = 2 + self.to = 1 + -- second arg, if a number, selects default outlet + if type(atoms[2]) == "number" then + self:in_2_float(atoms[2]) + end + return true +end + +function LDemux:in_2_float(f) + -- clip selection between left- and rightmost outlet + self.to = math.max(1, math.min(self.outlets, f)) +end + +function LDemux:in_1(s, m) + self:outlet(self.to, s, m) +end -- cgit v1.2.1