[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: ipairs in Lua 5.3.0-alpha
- From: Andrew Starks <andrew.starks@...>
- Date: Sat, 16 Aug 2014 12:49:03 -0500
On Saturday, August 16, 2014, Dirk Laurie <dirk.laurie@gmail.com> wrote:
2014-08-16 16:42 GMT+02:00 Andrew Starks <andrew.starks@trms.com>:
>
>
> On Saturday, August 16, 2014, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>>
>> 2014-08-16 16:23 GMT+02:00 Andrew Starks <andrew.starks@trms.com>:
>>
>> > What would be most useful to me, would be if ipairs returned all numeric
>> > key
>> > / value pairs, in order, regardless of holes.
>>
>> I can't see how implementing that in C would be possible in
>> a cleverer way than iterating over pairs and keeping what you
>> need. But the Lua extension I thought was off-topic would
>> do this for you:
>>
>> for k,v in pairs(tbl) if type(k)=='number' do
>> ...
>> end
>>
>
> Not in order.
Didn't see that. Then you will have to cache everything in a list
and sort it, since there is no way you can make a table like
{[130]='a',[292]='b'} etc retrieve the keys in order, even in C.
Yes, and that is what I do now and it works nicely, except that it means quite a bit of code.
I assert that ipairs is used when order matters. So, thinking about ipairs in terms of it being the ordinal iterator could be a useful mental framework.
[I often feel the need to state that I'm on a more facile level than most of you. Sometimes a naive point of view is helpful, though...]
Andrew
- References:
- Speed of # operator (Was: ipairs in Lua 5.3.0-alpha), Dirk Laurie
- Re: Speed of # operator (Was: ipairs in Lua 5.3.0-alpha), Enrico Colombini
- Re: Speed of # operator (Was: ipairs in Lua 5.3.0-alpha), Jan Behrens
- Re: Speed of # operator (Was: ipairs in Lua 5.3.0-alpha), Roberto Ierusalimschy
- Re: ipairs in Lua 5.3.0-alpha, Jan Behrens
- Re: ipairs in Lua 5.3.0-alpha, Jan Behrens
- Re: ipairs in Lua 5.3.0-alpha, Roberto Ierusalimschy
- Re: ipairs in Lua 5.3.0-alpha, Jan Behrens
- Re: ipairs in Lua 5.3.0-alpha, Jan Behrens
- Re: ipairs in Lua 5.3.0-alpha, Roberto Ierusalimschy
- Re: ipairs in Lua 5.3.0-alpha, Jan Behrens
- Re: ipairs in Lua 5.3.0-alpha, Doug Currie
- Re: ipairs in Lua 5.3.0-alpha, Coda Highland
- Re: ipairs in Lua 5.3.0-alpha, Jan Behrens
- Re: ipairs in Lua 5.3.0-alpha, Andrew Starks
- Re: ipairs in Lua 5.3.0-alpha, Andrew Starks
- Re: ipairs in Lua 5.3.0-alpha, Dirk Laurie
- Re: ipairs in Lua 5.3.0-alpha, Andrew Starks
- Re: ipairs in Lua 5.3.0-alpha, Dirk Laurie