lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 14/07/07, Merick <Merick_TeVaran@comcast.net> wrote:
Thanks, that works nicely. It should help me out with automating the
equalizer settings for the sound library I'm using.

One thing though, how do I need to change it to  get it to work for
something like this:

b = {op1 = 9,op2 = 8,op3 = 7,op4 = 6,op5 = 5}
eq.chan1 = b

Depends on what you want it to do... You should think well of the
structure you want to generate.

having eq mirror of _eq is not the same as having their fields mirror
each other.

try the recursive approach.

function get_rec_mirror(orig)
 return {
  __index = function(t,k)
      print("index",t,k)
      if  type(orig[k]~='table' then
        return orig[k]
      else
         local ret = {}
         setmetatable(ret, get_rec_mirror(orig[k])
         return ret
      end
  end,
    __newindex = function(t,k,v)
      print("newindex",t,k,v)
      orig[k] = v
  end
  }
end

this or something similar could work as you intend.


or even this:

preset1 = {
    chan1 = {op1 = 66,op2 = 66,op3 = 66,op4 = 4,op5 = 66},
    chan2 = {op1 = 66,op2 = 66,op3 = 66,op4 = 4,op5 = 66},
    chan3 = {op1 = 66,op2 = 66,op3 = 66,op4 = 4,op5 = 66}
    }

eq = preset1

this simply won't work, unless you set the metatable for globals which
you probably don't want.
Else just use a function that copies and sets metatables too according
to your wishes.

--mi