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

Apr 5, 2013 at 1:35am

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

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. –
#67545
Apr 15, 2013 at 9:37pm

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
#243037
Apr 15, 2013 at 9:52pm

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

#243038
Apr 16, 2013 at 5:30am

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

#243039

You must be logged in to reply to this topic.