aboutsummaryrefslogtreecommitdiff
path: root/examples/shared.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/shared.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/shared.pd_lua')
-rw-r--r--examples/shared.pd_lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/examples/shared.pd_lua b/examples/shared.pd_lua
new file mode 100644
index 0000000..b5d5dcd
--- /dev/null
+++ b/examples/shared.pd_lua
@@ -0,0 +1,34 @@
+local Shared = pd.Class:new():register("shared")
+local sharedStore = { }
+
+function Shared:initialize(sel, atoms)
+ if type(atoms[1]) == "string" then
+ if sharedStore[atoms[1]] == nil then
+ sharedStore[atoms[1]] = { sel = "bang", msg = { }, count = 1 }
+ else
+ sharedStore[atoms[1]].count = sharedStore[atoms[1]].count + 1
+ end
+ self.name = atoms[1]
+ self.inlets = 2
+ self.outlets = 1
+ return true
+ else
+ return false
+ end
+end
+
+function Shared:in_1_bang()
+ self:outlet(1, sharedStore[self.name].sel, sharedStore[self.name].msg)
+end
+
+function Shared:in_2(s, m)
+ local c = sharedStore[self.name].count
+ sharedStore[self.name] = { sel = s, msg = m, count = c }
+end
+
+function Shared:finalize()
+ sharedStore[self.name].count = sharedStore[self.name].count - 1
+ if sharedStore[self.name].count == 0 then
+ sharedStore[self.name] = nil
+ end
+end