aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMartin Peach <mrpeach@users.sourceforge.net>2012-04-03 20:24:54 +0000
committerIOhannes m zmölnig <zmoelnig@iem.at>2015-10-14 14:28:31 +0200
commitdf3ab06dfcfa99462c8d063a9ccd5d5160eb351c (patch)
tree858ce02fb5a822484110ace72558c513f6015dbc /examples
parent80ba9b7a2031d3159932eb9e306b3c110c01cea6 (diff)
Some drippers may work faster in lua than as abstarctions...
svn path=/trunk/externals/loaders/pdlua/; revision=16108
Diffstat (limited to 'examples')
-rw-r--r--examples/llist-drip-help.pd34
-rw-r--r--examples/llist-drip.pd_lua39
-rw-r--r--examples/lsymbol-drip-help.pd111
-rw-r--r--examples/lsymbol-drip.pd_lua56
4 files changed, 240 insertions, 0 deletions
diff --git a/examples/llist-drip-help.pd b/examples/llist-drip-help.pd
new file mode 100644
index 0000000..cd7fc6a
--- /dev/null
+++ b/examples/llist-drip-help.pd
@@ -0,0 +1,34 @@
+#N canvas 390 515 588 334 10;
+#X declare -lib pdlua;
+#X obj 199 247 llist-drip;
+#X obj 89 10 import pdlua;
+#X msg 99 130 1 2 3 a b c;
+#X msg 121 152 list twig branch root;
+#X floatatom 77 109 5 0 0 0 - - -;
+#X obj 199 274 print dripped;
+#X symbolatom 36 68 10 0 0 0 - - -;
+#X obj 36 44 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
+-1;
+#X obj 56 89 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
+-1;
+#X msg 187 218 alpha;
+#X msg 165 196 list alpha;
+#X text 227 42 [llist-drip] outputs any input as a sequence;
+#X text 375 292 by Martin Peach \, 2012_04_03;
+#X msg 143 174 alpha beta gamma 1.234 -2;
+#X text 307 173 <- a message is interpreted as a list;
+#X text 259 152 <- a true list;
+#X text 239 196 <- a list with one element is still a list;
+#X text 229 217 <- a message is taken to be a oone-element list;
+#X text 178 130 <- a list beginning with a float is still a list;
+#X text 137 81 <- any single items are passed through unchanged;
+#X connect 0 0 5 0;
+#X connect 2 0 0 0;
+#X connect 3 0 0 0;
+#X connect 4 0 0 0;
+#X connect 6 0 0 0;
+#X connect 7 0 6 0;
+#X connect 8 0 0 0;
+#X connect 9 0 0 0;
+#X connect 10 0 0 0;
+#X connect 13 0 0 0;
diff --git a/examples/llist-drip.pd_lua b/examples/llist-drip.pd_lua
new file mode 100644
index 0000000..1d2fe79
--- /dev/null
+++ b/examples/llist-drip.pd_lua
@@ -0,0 +1,39 @@
+--[[
+ llist-drip
+ Output a list as a sequence of elements, same as [list-abs/list-drip]
+ author Martin Peach 20120403
+--]]
+
+-- Pd class
+
+local LlistDrip = pd.Class:new():register("llist-drip")
+local selectormap = {string = "symbol", number="float", userdata="pointer"} -- for lua/Pd type conversion
+
+function LlistDrip:initialize(name, atoms)
+ self.inlets = 1
+ self.outlets = 1
+ return true
+end
+
+function LlistDrip:in_1(sel, atoms) -- anything
+ --pd.post("sel is " .. sel);
+ --pd.post("number of atoms is ".. #atoms)
+ --for i,v in ipairs(atoms) do
+ -- pd.post(i .. " = " .. v)
+ --end
+ if sel == "list" then -- the usual case
+ for i=1, #atoms do
+ -- map lua types to pd selectors
+ self:outlet(1, selectormap[type(atoms[i])], {atoms[i]})
+ end
+ elseif sel == "float" or sel == "symbol" or sel == "pointer" or sel == "bang" then -- single element "lists"
+ self:outlet(1, sel, {atoms[1]})
+ else -- messages are lists beginning with a selector
+ self:outlet(1, selectormap[type(sel)], {sel})
+ for i=1, #atoms do
+ self:outlet(1, selectormap[type(atoms[i])], {atoms[i]})
+ end
+ end
+end
+-- end of llist-drip
+
diff --git a/examples/lsymbol-drip-help.pd b/examples/lsymbol-drip-help.pd
new file mode 100644
index 0000000..1a5e1d1
--- /dev/null
+++ b/examples/lsymbol-drip-help.pd
@@ -0,0 +1,111 @@
+#N canvas 535 299 684 437 10;
+#X declare -lib pdlua;
+#X obj 23 8 import pdlua;
+#X obj 166 218 lsymbol-drip;
+#X msg 24 59 what;
+#X symbolatom 121 157 10 0 0 0 - - -;
+#X obj 91 141 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
+-1;
+#X msg 73 108 symbol qwertyuiop;
+#X obj 166 253 print dripped;
+#X text 234 284 by Martin Peach 2012_04_03;
+#X text 258 218 [lsymbol-drip] spits out the characters of a symbol.
+;
+#X msg 45 80 why not;
+#X text 98 79 <- but a message is rejected;
+#X text 58 59 <- a lone selector is taken to be a symbol;
+#X text 216 181 <- unicode should be handled correctly;
+#X obj 43 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 237 286 sel a b c d e f g h i j k l m n o p q r s t u v w x
+y z;
+#X obj 63 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 83 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 103 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 123 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 143 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 163 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 183 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 203 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 223 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 243 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 263 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 283 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 303 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 323 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 343 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 363 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 383 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 403 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 423 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 443 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 463 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 483 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 503 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 523 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 543 314 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X msg 146 181 symbol zéyé;
+#X text 430 404 by Martin Peach 2012_04_03;
+#X msg 121 130 set Who;
+#X symbolatom 564 314 10 0 0 0 - - -;
+#X connect 1 0 6 0;
+#X connect 1 0 14 0;
+#X connect 2 0 1 0;
+#X connect 3 0 1 0;
+#X connect 4 0 3 0;
+#X connect 5 0 1 0;
+#X connect 9 0 1 0;
+#X connect 14 0 13 0;
+#X connect 14 1 15 0;
+#X connect 14 2 16 0;
+#X connect 14 3 17 0;
+#X connect 14 4 18 0;
+#X connect 14 5 19 0;
+#X connect 14 6 20 0;
+#X connect 14 7 21 0;
+#X connect 14 8 22 0;
+#X connect 14 9 23 0;
+#X connect 14 10 24 0;
+#X connect 14 11 25 0;
+#X connect 14 12 26 0;
+#X connect 14 13 27 0;
+#X connect 14 14 28 0;
+#X connect 14 15 29 0;
+#X connect 14 16 30 0;
+#X connect 14 17 31 0;
+#X connect 14 18 32 0;
+#X connect 14 19 33 0;
+#X connect 14 20 34 0;
+#X connect 14 21 35 0;
+#X connect 14 22 36 0;
+#X connect 14 23 37 0;
+#X connect 14 24 38 0;
+#X connect 14 25 39 0;
+#X connect 14 26 43 0;
+#X connect 40 0 1 0;
+#X connect 42 0 3 0;
diff --git a/examples/lsymbol-drip.pd_lua b/examples/lsymbol-drip.pd_lua
new file mode 100644
index 0000000..59b0c67
--- /dev/null
+++ b/examples/lsymbol-drip.pd_lua
@@ -0,0 +1,56 @@
+--[[
+ lsymbol-drip
+ Output a symbol as a sequence of characters
+ author Martin Peach 20120403
+--]]
+
+-- Pd class
+
+local LsymbolDrip = pd.Class:new():register("lsymbol-drip")
+
+function LsymbolDrip:initialize(name, atoms)
+ self.inlets = 1
+ self.outlets = 1
+ return true
+end
+
+-- LsymbolDrip:drip: accumulate possibly multibyte characters from buf and output them as symbols
+function LsymbolDrip:drip(buf)
+ --pd.post(buf.. " size " .. #buf)
+ local i = 1, j, b
+ local len = #buf
+
+ while i <= len do
+ j = i -- character is one byte long
+ b = string.byte(buf, i)
+ --pd.post("*b is " .. b .. " i is " .. i)
+ while b > 0x7f and j < len do -- multibyte characters have their high bit set
+ j = j + 1
+ b = string.byte(buf, j)
+ --pd.post("_b is " .. b .. " j is " .. j)
+ end
+ if j ~= i and j < len then j = j - 1 end -- j was pointing to the next character
+ self:outlet(1, "symbol", {string.sub(buf, i, j)})
+ i = j + 1 -- start of next character
+ end
+end
+
+function LsymbolDrip:in_1(sel, atoms) -- anything
+ --pd.post("sel is " .. sel);
+ --pd.post("number of atoms is ".. #atoms)
+ --for i,v in ipairs(atoms) do
+ -- pd.post(i .. " = " .. v)
+ --end
+ local buf
+ if sel == "symbol" then -- the usual case
+ buf = tostring(atoms[1])
+ self:drip(buf)
+ elseif #atoms == 0 then -- a selector
+ buf = tostring(sel)
+ self:drip(buf)
+ else -- reject non-symbols
+ self:error("lsymbol-drip: input not a symbol")
+ end
+end
+-- end of lsymbol-drip
+