formatting lists in jit.gl.lua

John J.A. Jannone's icon

Dear all,

I am using these Lua scripts to update the motion of objects in a gl world, but I can't seem to format the output lists so that I don't need to use a zl.join when I get back to Max. Any help is appreciated!

John

--begin LUA script example-orbit.lua

this.outlets=2
local S = 1.
local Sc = 1.

function speed(v)
    S = v
end

function size(v)
    Sc = v
end

function list(...)
local values = {...}
    local message={}

    values[5] = Sc*values[10]*(math.sin(2*math.pi*values[9]))
    values[6] = Sc*values[11]*(math.cos(2*math.pi*values[9]))
    values[7] = 0.
    values[9] = values[9]+S*((values[8]-.5)/100.)

    message={"setcell", INT, "val"}

    outlet(0,message)
    outlet(1,values)

    end

function int(v)
INT=v
end

--end LUA example-orbit.lua

--begin LUA example3.lua

this.outlets=2

function list(...)
local values = {...}
    local message={}

    values[5] = values[5]*2.-1
    values[6] = values[6]*2.-1
    values[7] = values[7]*2.-1

    values[11] = values[10]

    message={"setcell", INT, "val"}

    outlet(1,values)
    outlet(0,message)

    end

function int(v)
INT=v

end

--end LUA example3.lua

Max Patch
Copy patch and select New From Clipboard in Max.

Here is the patch in which I'm using these scripts:

John J.A. Jannone's icon

Aha -- solved it. Here's how to join tables (lists) in Lua where RIGHT and LEFT are two tables to be joined:

    for k,v in ipairs(RIGHT) do LEFT[#LEFT+1]=v end    

J

Wesley Smith's icon

You got it. You can also do:

for i=1, #RIGHT do
LEFT[#LEFT+1] = RIGHT[i]
end

John J.A. Jannone's icon

Thank you Wesley!