aboutsummaryrefslogtreecommitdiff
path: root/examples/peekbag.pd_lua
diff options
context:
space:
mode:
authorMartin Peach <mrpeach@users.sourceforge.net>2011-03-15 20:53:57 +0000
committerMartin Peach <mrpeach@users.sourceforge.net>2011-03-15 20:53:57 +0000
commit267170167d52cab9e97f879d9127a1cf04f6bb58 (patch)
tree00260a90ce6472e34c5eff41602af57595c8830d /examples/peekbag.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/peekbag.pd_lua')
-rw-r--r--examples/peekbag.pd_lua69
1 files changed, 69 insertions, 0 deletions
diff --git a/examples/peekbag.pd_lua b/examples/peekbag.pd_lua
new file mode 100644
index 0000000..15e4791
--- /dev/null
+++ b/examples/peekbag.pd_lua
@@ -0,0 +1,69 @@
+-- contributed by Frank Barknecht
+
+local PeekBag = pd.Class:new():register("peekbag")
+
+function PeekBag:initialize(name, atoms)
+ self.inlets = 2
+ self.outlets = 1
+ self.bag = {}
+ self.add = false
+ return true
+end
+
+function PeekBag:in_1_float(f)
+ if self.add then
+ table.insert(self.bag, f)
+ else
+ for i=table.getn(self.bag),1,-1 do
+ if self.bag[i]==f then
+ table.remove(self.bag, i)
+ break
+ end
+ end
+ end
+end
+
+function PeekBag:in_1_list(l)
+ if type(l[2]) == "number" then
+ self:in_2_float(l[2])
+ end
+ if type(l[1]) == "number" then
+ self:in_1_float(l[1])
+ end
+end
+
+function PeekBag:in_1_clear(l)
+ self.bag = {}
+ self.add = false
+end
+
+function PeekBag:in_1_flush(l)
+ self:in_1_bang()
+ self:in_1_clear()
+end
+
+function PeekBag:in_2_float(f)
+ if f == 0 then
+ self.add = false
+ else
+ self.add = true
+ end
+end
+
+function PeekBag:in_1_bang()
+ -- print all values of array
+ for i,v in ipairs(self.bag) do
+ self:outlet(1, "float", {v})
+ end
+end
+
+function PeekBag:in_1_aslist()
+ -- print all values of array as list
+ if table.getn(self.bag) == 1 then
+ self:outlet(1, "float", {self.bag[1]})
+ elseif table.getn(self.bag) > 1 then
+ self:outlet(1, "list", self.bag)
+ end
+end
+
+