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/list-pak.pd_lua | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 examples/list-pak.pd_lua (limited to 'examples/list-pak.pd_lua') diff --git a/examples/list-pak.pd_lua b/examples/list-pak.pd_lua new file mode 100644 index 0000000..1651582 --- /dev/null +++ b/examples/list-pak.pd_lua @@ -0,0 +1,56 @@ +--[[ + +list-pak + + Like [pack] for any kind of type. Argument specifies number of inlets. All + inlets are hot (as in Max' [pak]) + + --Written by Frank Barknecht + +--]] + +-- Some footils -- + +-- selectors +local selectors = {"float", "list", "symbol", "bang", "pointer"} + +-- check if item x is in table t: +local function contains(t, x) + for _,v in ipairs(t) do + if v == x then return true end + end + return false +end + +-- Pd class + +local ListPak = pd.Class:new():register("list-pak") + +function ListPak:initialize(name, atoms) + self.outlets = 1 + self.stored = {} + if atoms[1] == nil then + self.inlets = 1 + elseif type(atoms[1]) == "number" and atoms[1] >= 0 then + self.inlets = math.max(atoms[1], 1) + else + pd.post("list-pak: First arg must be a positive float or empty") + return false + end + for i=1,self.inlets do + table.insert(self.stored, 0) + end + return true +end + +function ListPak:in_n(i, sel, atoms) + if not contains(selectors, sel) then + -- insert selector + self.stored[i] = sel + else + if table.getn(atoms) > 0 then + self.stored[i] = atoms[1] + end + end + self:outlet(1, "list", self.stored) +end -- cgit v1.2.1