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
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
i realize this doesn't really answer your question.
unfortunately, i know close to nothing about lua.
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