lua-users home
lua-l archive

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



but.. if the code says "for i,v in pairs(t) do" then the overloading would work already now?


7.2.2005 kello 13:44, Steve Donovan kirjoitti:

 asko.kauppi@sci.fi 02/07/05 12:32PM >>>

Why so complicated?
   pairs = function( t )
        local mt = getmetatable( t )
        return ( ( mt and mt.__pairs ) or raw_pairs )( t )
    end

It would be very cool if 'for i,v in t do...'
would use the global pairs() function;  that would
(a) make quite explicit what the for-loop means
if t isn't an iterator function and (b) make interesting
overloading possible, such as above.

steve d.