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;
_______________________________________________
[email protected] mailing list
UNSUBSCRIBE and account-management -> 
http://lists.puredata.info/listinfo/pd-list

Reply via email to