aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Peach <mrpeach@users.sourceforge.net>2012-04-19 19:06:41 +0000
committerIOhannes m zmölnig <zmoelnig@iem.at>2015-10-14 14:28:31 +0200
commit869a2ec9dc40ec39d6833e1bd8eaeaf630216e5a (patch)
tree7ff6df607faff24ab0eabb688c57764c1cea6d3d
parentdf3ab06dfcfa99462c8d063a9ccd5d5160eb351c (diff)
A version of list-abs' [list-rdrip] in lua
svn path=/trunk/externals/loaders/pdlua/; revision=16128
-rw-r--r--examples/llist-rdrip-help.pd35
-rw-r--r--examples/llist-rdrip.pd_lua39
2 files changed, 74 insertions, 0 deletions
diff --git a/examples/llist-rdrip-help.pd b/examples/llist-rdrip-help.pd
new file mode 100644
index 0000000..4627bf8
--- /dev/null
+++ b/examples/llist-rdrip-help.pd
@@ -0,0 +1,35 @@
+#N canvas 392 517 588 334 10;
+#X declare -lib pdlua;
+#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 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 text 375 292 by Martin Peach \, 2012_04_19;
+#X text 196 37 [llist-rdrip] outputs any input as a reverse sequence
+;
+#X obj 199 247 llist-rdrip;
+#X connect 1 0 19 0;
+#X connect 2 0 19 0;
+#X connect 3 0 19 0;
+#X connect 5 0 19 0;
+#X connect 6 0 5 0;
+#X connect 7 0 19 0;
+#X connect 8 0 19 0;
+#X connect 9 0 19 0;
+#X connect 10 0 19 0;
+#X connect 19 0 4 0;
diff --git a/examples/llist-rdrip.pd_lua b/examples/llist-rdrip.pd_lua
new file mode 100644
index 0000000..5d07dfd
--- /dev/null
+++ b/examples/llist-rdrip.pd_lua
@@ -0,0 +1,39 @@
+--[[
+ llist-rdrip
+ Output a list as a sequence of elements in reverse order
+ author Martin Peach 20120419
+--]]
+
+-- Pd class
+
+local LlistRdrip = pd.Class:new():register("llist-rdrip")
+local selectormap = {string = "symbol", number="float", userdata="pointer"} -- for lua/Pd type conversion
+
+function LlistRdrip:initialize(name, atoms)
+ self.inlets = 1
+ self.outlets = 1
+ return true
+end
+
+function LlistRdrip: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 = #atoms, 1, -1 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 = #atoms , 1 , -1 do
+ self:outlet(1, selectormap[type(atoms[i])], {atoms[i]})
+ end
+ end
+end
+-- end of llist-rdrip
+