lua-users home
lua-l archive

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


Why does foo need to be a table at all in this example? Why not make it a object with multi-arg get and set methods?

You're already signing yourself up for a function to implement the functionality, trying to hide it behind lua syntax doesn't seem like a particularly big win, though perhaps I'm missing something clever?

Daniel.

Chris wrote:
How hard would it be to modify the parser so that the index and
newindex metamethods could have multiple parameters?

Usage would be something like:

   foo[1, 2, 3] = 4

I suppose in the case of newindex it would make sense to pass the
value it's setting in the same position with extra parameters
trailing.  Ideally it would be earilier but for compatibility it would
have to be similar to the old method.

   function foo.__newindex(obj, idx1, value, idx2, idx3 ...)
      ...
   end

I realize it's possible to just pass a table but this has performance
problems for me compared to regular indexing.  Actually I'm not sure
what kind of performance penalty this multiple parameter indexing
might have but I wouldn't think it would be any worse than a function
call (?).

CR