[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: A proposal for the confusing pseudo table ≈ array concept
- From: Sean Conner <sean@...>
- Date: Fri, 19 Jan 2018 23:23:46 -0500
It was thus said that the Great Elias Hogstvedt once stated:
> In a way we have 2 fundamental types already. The entire table library
> assumes that the table passed is treated as an array type. This separation
> has grown more since table.pack and table.unpack was introduced. Ipairs
> work on arrays and pairs work on everything else, now there're only pairs.
pairs() works on arrays---it always has. It's just that if the underlying
table contains a sequence and other fields, pairs() will iterate over all
the indicies:
foo = { 1 , 2 , 3 , one = 1 , two = 2 , three = 3 }
for key,value in pairs(foo) do print(key,value) end
1 1
2 2
3 3
three 3
one 1
two 2
Also, Lua 5.2 introduced two new metamethods, __pair and __ipairs. Lua
5.3 dropped __ipairs because PUC felt it wasn't needed.
-spc