formatting lists in jit.gl.lua


    Feb 23 2013 | 12:58 am
    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
    Here is the patch in which I'm using these scripts:

    • Mar 08 2013 | 1:19 pm
      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
    • Mar 08 2013 | 11:59 pm
      You got it. You can also do:
      for i=1, #RIGHT do LEFT[#LEFT+1] = RIGHT[i] end
    • Mar 11 2013 | 12:45 am
      Thank you Wesley!