lua-users home
lua-l archive

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


Hi, All.

The Lua 5.1 Reference Manual describes #t to be SOME n, so t[n] is not nil and t[n+1] is nil. So the following two tables have a different result by #-Operator:
----
a = {1,2,3,nil,nil,6}
b = {}
b[1] = 1
b[2] = 2
b[3] = 3
b[6] = 6
print (#a,#b)
6       3
----
Ok - fine, but it seems to have some consequences: if I apply table.remove at first position of both tables - the number of keys to be shifted seems to be different.
----
for k,v in pairs(a) do print(k,v) end
1       1
2       2
3       3
6       6
for k,v in pairs(b) do print(k,v) end
1       1
2       2
3       3
6       6
table.remove(a,1); table.remove(b,1)
print (#a,#b)
2       2
for k,v in pairs(a) do print(k,v) end
1       2
2       3
5       6
for k,v in pairs(b) do print(k,v) end
1       2
2       3
6       6
----
>From user point of view is the behaviour of the table.remove function undefined. Is it a feature or a bug?
 --
Wladimir Krawtschunowski
Software developer

Vectron Systems AG
Willy-Brandt-Weg 41
48155 Münster, Germany
Tel.: +49/251/28 56-0

--- 
Vectron Systems AG, Willy-Brandt-Weg 41, 48155 Münster, Germany, Phone +49-251-2856-0, Fax +49-251-2856-560, 
Amtsgericht Münster HRB 10502, Vorstand / Board of Management: Jens Reckendorf, Thomas Stümmler, 
Aufsichtsrat / Supervisory Board: Christian Ehlers (Vorsitz / Chairman)