[PD] manipulation of text files - grep - shell - coll

Frank Barknecht fbar at footils.org
Sat Jan 19 12:19:04 CET 2008

robcanning hat gesagt: // robcanning wrote:

> well my programming skills don't really extend far pass writing the odd 
> bash script but yes, writing an objectclass would be ideal (you mean a 
> pd objectclass?) any pointers on where to start with this using python?

Unless you already have pyext installed, I think installing the Lua
loader is a bit easier. You need to check it out from the subversion
repo at goto10, install the lua5.1-dev packages for your distro, then
on Linux a simple "make" should compile it. Load it with "-lib lua".

Learning Lua or Python is useful in other contexts as well, and
actually it's not that hard to turn that knowledge into a Pd object
class. You may want to start at http://lua-users.org/wiki/LuaTutorial

IMO writing shell scripts is harder than writing Lua/Python scripts.

The general structure for both Python and Lua Pd classes is very
simple. I attached a quickie demonstrating this for Lua: "ltxt" is a
kind of simplified "coll" or "textfile", where you can store data
under float and symbol keys and look it up again. Starting with that
it's easy to extend this with methods to search for keys, sort the
data storage array etc, delete data where keys match a certain pattern
etc. The example is more meant to illustrate the general structure of
a Lua Pd class than as a real object to use.

 Frank Barknecht                                     _ ______footils.org__
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ltxt-help.pd
Type: application/puredata
Size: 939 bytes
Desc: not available
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20080119/ee33c633/attachment.bin>
-------------- next part --------------
-- ltxt: a simple hash type for Pd written in Lua.

local NAME_OF_CLASS = "ltxt" -- should be equal to the name of this file minus suffix

-- register this class with Pd as NAME_OF_CLASS
local M = pd.Class:new():register(NAME_OF_CLASS)

-- M now is used as the name for the class in this file.

function M:initialize(name, args)
    self.outlets = 2
    self.inlets = 1
    self.mydata = {} -- empty table to store whatever
    return true

-- lookup key in mydata, bang second outlet if not found:
function M:lookup(x)
    if self.mydata[x] then
        self:outlet(1, "list", self.mydata[x])
        self:outlet(2, "bang", {})

-- float and symbol methods will look up key in mydata table:
function M:in_1_float(x)

function M:in_1_symbol(x)

-- what to do on "add [atoms]" into 1st inlet:
function M:in_1_add(atoms)
    local key = table.remove(atoms, 1) -- pop first element of "atoms" into "key"
    self.mydata[key] = atoms

-- what to do on "print" into 1st inlet:
function M:in_1_print()
    for k,v in pairs(self.mydata) do
        pd.post(k .. ": " .. table.concat(self.mydata[k], " "))

-- what to do on "reset" into 1st inlet:
function M:in_1_reset()
    self.mydata = {}

More information about the Pd-list mailing list