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 Jonathan Goble once stated:
> A new type would have many advantages, chief among them elimination of
> the need to store the length as a field in the table or metatable
> (since the length would now be known and tracked by the C internals),
> and elimination of the question of how to set the initial length from
> a constructor (since array constructors probably wouldn't allow
> explicit keys/indices).

  There exist a few ways right now to construct a valid Lua sequence.  They
are:

	x = { 1 , 2 , 3 }
	x = { [1] = 1 , [2] = 2 , [3] = 3 } -- can be out of order
	x = {}	x[1] = 1	-- can be out of order
		x[2] = 2
		x[3] = 3
	x = {}	x[#x+1] = 1 
		x[#x+1] = 2
		x[#x+1] = 3
	x = {}	table.insert(x,1)
		table.insert(x,2)
		table.insert(x,3)

and I have existing code that uses all these methods (second one most often
when I'm constructing a table of anonymous functions, just to be explicit;
and in order---I'm not *that* crazy enough to define them out of order).

  Moving on, which ways should be supported, and which ones dropped?

  -spc (And I think that covers all the methods of making a sequence)