lua-users home
lua-l archive

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


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

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

I tried just using setmetatable(eq, get_mt_mirror(_eq)), but that seems to remove the metatables from the subtables.

"Mauro Iazzi" <mauro.iazzi@gmail.com>  wrote:
In the __index and __newindex you are getting/setting the fields of
_eq, not those of _eq.chain*.
check

print(eq.chan1.chan2)

even before setting anytihg in the tables, just after the setmetatable
statements.

You should make the metatable aware of which mirror it should use. I
would try a generator function approach. It would make easy to do it
all automatically with a metatable for eq.

It would work like this

function get_mt_mirror(orig)
  return {
   __index = function(t,k)
       print("index",t,k)
       return orig[k]
   end,
     __newindex = function(t,k,v)
       print("newindex",t,k,v)
       orig[k] = v
   end
   }
end

setmetatable(eq.chan1, get_mt_mirror(_eq.chan1))
print(eq.chan1.op3)

cheers,

--mi