lua-users home
lua-l archive

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


Because next isn't just an implementation detail at this point. It's a
global function and if one wants to override pairs, one might want to
override next. Given that, it would be nice if the override logic for pairs
would recognize a __next override so that programmers wouldn't have to
override both and so that a table iteration with an overridden next wouldn't
do more metatable lookups than necessary.

The simpler proposal would work if next were removed from the standard API
though I might then want an equivalently lightweight way to test for an
empty table.

Mark

on 2/7/05 2:32 AM, Asko Kauppi at asko.kauppi@sci.fi wrote:

> 
> Why so complicated?
> 
> I must be missing something, since isn't 'next()' just an
> implementation detail of 'pairs' and 'ipairs'.  I mean, if I want to
> redefine those to actually support '__[i]pairs' metamethods, wouldn't
> this be sufficient:
> 
>    pairs = function( t )
>        local mt = getmetatable( t )
>        return ( ( mt and mt.__pairs ) or raw_pairs )( t )
>    end
> 
>    ipairs = function( t )
>        local mt = getmetatable( t )
>        return ( ( mt and mt.__ipairs ) or raw_ipairs )( t )
>    end