[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua-5.1-alpha: length operator on tables (arrays) and nil values
- From: Michael Roth <mroth@...>
- Date: Fri, 16 Sep 2005 01:21:10 +0200
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Luiz Henrique de Figueiredo wrote:
> The new # operator does the right thing for
> tables that are used to represent vectors without holes. And it does not
> promise to give you anything useful otherwise.
Ok, but then lua needs a standard library wich makes it possible to use
vectors with holes.
In lua 4 there was the concept of t.n.
In lua 5 t.n was deprecated and we there are table.setn() and
table.getn(). Table.insert() was able to insert nils in a vector and
updated the internal N.
Now, in lua 5.1-alpha table.insert() ist deprecated and its semantic
changed. Table.insert() no longer updates the internal N of a vector
because there isn't such a thing like an internal N and because of this
it makes no sense for table.insert() to insert nils.
In my eyes functionality got lost.
So in 5.1 we schould stick with the lua 4 way and do all the work
manually with t.n? Remember 't[#t+1] = xyz' is useless if t has holes.
An intresting side note: Even in lua 5.1-alpha the argument table 'arg'
in vararg functions has an arg.n:
function a(...)
print(arg.n)
end
The above code works in both, 5.0.2 and 5.1-alpha. The following only
works in 5.0.2:
function b(...)
print(table.getn(arg))
end
In my eyes this different behaviour will produce a lot of surprising
results when switching from 5.0.2 to 5.1.
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFDKgHlSIrOxc3jOmoRAiZ/AJ9CcirvH/JVj0XOCOifNxTlJOtqXACeJHvn
ybVbzHWjeaKXalFpAC/RJm8=
=cWLB
-----END PGP SIGNATURE-----