Forums > Jitter

Correct use of jit.listener in jit.gl.lua

April 5, 2013 | 1:35 am

I am trying to do a simple getcell on a named matrix in jit.gl.lua, and I think I am using the jit.listener incorrectly. Can someone give me some guidance?

Lua script and max patch are below.

Thanks,

-John

–begin LUA

this.outlets=2

function getcell(x,y)

labymatrix = jit.matrix("laby")
listener = jit.listener(labymatrix.name, "listen")
labymatrix:getcell(x,y)

end

–the "listener" function
function listen(event)
outlet(1, event.subjectname)
outlet(0, table.concat(event.args, ", "))
end

–end LUA

– Pasted Max Patch, click to expand. –

April 15, 2013 | 9:37 pm

this works for me

--begin LUA

this.outlets=2

function getcell(x,y)

labymatrix = jit.matrix("laby")
print(labymatrix:getcell(x,y))

end

--end LUA

April 15, 2013 | 9:52 pm

i realize this doesn’t really answer your question.
unfortunately, i know close to nothing about lua.


April 16, 2013 | 5:30 am

Thanks Rob — this lead me to the solution!

For reasons I don’t understand, the call to the variable containing the matrix has to be an argument to a function, like so:


--begin LUA

this.outlets=2

outputA={}
outputB={}

function eval(...)
outputA={...}
end

function getcell(x,y)

labymatrix = jit.matrix("laby")

--this works
eval(labymatrix:getcell(x,y))
-- end works

--this doesn't work
outputB = labymatrix:getcell(x,y)
--end doesn't work

outlet(0, outputA)
outlet(1, outputB)

end

--end LUA

You’re right, this doesn’t really show me how to use jit.listener — but it shows me that at least in this case I don’t need it! Yip!

-J


Viewing 4 posts - 1 through 4 (of 4 total)