[PD] pdlua output
robcanning
robcanning at eircom.net
Wed Jan 23 15:41:11 CET 2008
also, the code works in lua but not in the pdlua object
somewhere i am getting mixed up between floats lists strings atoms
tables etc. but i cant see where
here is the working lua code
> tbl = {}
> table.insert(tbl, '1, s22df, 1, score = 3')
> table.insert(tbl, '1, s22df, 1, score = 2')
> table.insert(tbl, '1, s22df, 1, score = 1')
> for i, v in ipairs(tbl) do if string.match(v, "score = 1", 1, true)
then print(v) end end
1, s22df, 1, score = 1
thanks
rob
> i'll clarify a bit...
> i add a list to a table with:
>
> -- "insert [list]" into 1st inlet:
> function M:in_1_insert(list)
> table.insert(self.mydata, list)
> end
>
> then i search the table for the pattern "score = 1" and ask it to
> print the lines containing the matched pattern
>
> -- what to do on "scores" into 1st inlet:
> function M:in_1_scores()
> for i, v in ipairs(self.mydata) do
> if string.match(v, "score = 1", 1, true) then
> self:outlet(1, "list", v) end
> end
> end
>
> the problem is that the string.match is expecting a string and getting
> a table and i'm not sure how to fix this - i thought the ipairs was
> iterating the table into a string but its not.
>
> here is the error from pd:
> [string "rob2"]:19: bad argument #1 to 'match' (string expected, got
> table)
>
> lua and lua files attached
>
> any guidance welcome,
>
> thanks
>
> rob c
> ------------------------------------------------------------------------
>
> local NAME_OF_CLASS = "rob2"
> local M = pd.Class:new():register(NAME_OF_CLASS)
>
> function M:initialize(name, args)
> self.outlets = 2
> self.inlets = 1
> self.mydata = {}
> return true
> end
>
> -- "insert [list]" into 1st inlet:
> function M:in_1_insert(list)
> table.insert(self.mydata, list)
> end
>
> -- what to do on "scores" into 1st inlet:
> function M:in_1_scores()
> for i, v in ipairs(self.mydata) do
> if string.match(v, "score = 1", 1, true) then
> self:outlet(1, "foo", v) end
> end
> end
>
> -- 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], " "))
> end
> end
>
> -- what to do on "reset" into 1st inlet:
> function M:in_1_reset()
> self.mydata = {}
> end
>
> ------------------------------------------------------------------------
>
> #N canvas 123 334 512 437 10;
> #X msg 52 64 print;
> #X msg 53 86 scores;
> #X obj 17 131 rob2;
> #X msg 17 43 insert s d d d 2 2 2 2 w score = 1;
> #X msg 54 106 reset;
> #X obj 17 161 prepend set;
> #X msg 17 183;
> #X obj 17 11 loadbang;
> #X connect 0 0 2 0;
> #X connect 1 0 2 0;
> #X connect 2 0 5 0;
> #X connect 3 0 2 0;
> #X connect 4 0 2 0;
> #X connect 5 0 6 0;
> #X connect 7 0 3 0
>
More information about the Pd-list
mailing list