[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: table.getn in Lua 5.0.2/3
- From: Stefan Brantschen <sbr@...>
- Date: Fri, 15 Sep 2006 07:19:33 +0200
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 14 Sep 2006, at 17:37, David Given wrote:
As soon as you start setting numeric elements to nil, or even if you
start setting them beyond the end of the array, then it's not a valid
array any more and all these things start producing undefined
behaviour.
All true. But as long as you know what you're doing, arrays with
holes can be handled just well (cf. also PIL II, p16). For example, a
table representing breakpoints in a file in a debugger, like
breakpoints = {some_file_name = {2 = true, 25 = true}, other_file = ..}
is just handy. Of course, you need to be aware that certain operators
and functions don't work correctly. But sometimes you _want_ to set a
numerically indexed table element to nil, and not use table.remove()
- -- see the above example.
Lua 5.1 also has new function table.maxn() that works with arrays
with holes.
With regards
- - Stefan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (Darwin)
iQEVAwUBRQo35TqiXtt/m8NcAQIFrwgAqO8fgrkgLyYmwHiXPc1UOdu+afn89V89
fpDUSXasvFA6relYtK07fySTLC3DldmKWadGfNNK1tcpFggIJTc5R+zzuy4Ys+0V
Rh1fCQmaYF9+c993kjVcJZkUxVG7de80eH9dqK9MlgJ5bqh9rcCiSVn2rgXwqzJH
EblFu09WBEsEWHgCI3bNTuGMyB/mqD3uusCPnhpMqkBN8AXoIYEqrNOyDC0c5sIw
Hq+xc9Qoq/YBokgY5rOoLJ2vK4AqYbBmIm5Pgpf79UNnFAFcSyxjmm2u9zTxC2Ce
n7tCflZRhquOXTl9q6dWTmIuyLBecq5QaqlAX7n0D/KdPKqZGZ9McQ==
=Jo97
-----END PGP SIGNATURE-----