lua-users home
lua-l archive

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


On Wed, Jun 11, 2014 at 6:43 PM, Kalafut, Bennett
<bennett.kalafut@thermofisher.com> wrote:
> Any thoughts on why this isn't so?  And is there a Lua hack (aside from memorization of the results of a proxy table) to make an array-like object with an __index metamethod but no array data work with table.unpack()


you could always do something like this (untested!)

do
   local oldfunc = {__unpack = table.unpack}
   table.unpack = function(o)
      return ((getmetatable(o) or oldfunc).__unpack or oldfunc.__unpack)(o)
   end
end

and then set any unpack()-like function on your object's __unpack metamethod

-- 
Javier