lua-users home
lua-l archive

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


Hi all (enumerated... :-)

OK, I will make an iterator function that does the trick.
The basic idea is that the table is enumerated once with pairs() to get the maximum integer key being used. Then the iterator function gets this as upvalue to correctly terminate. With each iteration it increments its own index counter and returns the indx and value from table, if existant, else the result of its (tail-)recursive recursion call.

For very sparse arrays, another approach might be faster:
at first run through the table with pairs() collecting all integer indexes in a new index array, and sort that. The iterator gets this as upvalue to walk through and pick the actual array values using this index table.


give me a day or so...

--
Oliver

Am 21.07.2016 um 21:50 schrieb Russell Haley:
Perhaps posting an example for people to follow would help lessen some of the "noise"? I've written some neat stuff in Lua but would have no clue how to move forward with your suggestion. Maybe the people making the noise aren't as experienced as you are? However, to support your argument that this does not belong in the base library, I have found that external packages are almost *more* important than the base because Lua is so lean (which I think is a good thing). Russ