lua-users home
lua-l archive

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


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