[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Sparse numeric arrays in lua 5
- From: "Milano Carvalho" <milanogc@...>
- Date: Sat, 29 Mar 2003 21:19:18 -0300
Hi,
I don't know why the table constructor, in Lua 5, doesn't set the total
number of elements when there is a nil value among them.
I think you will need set the number of elements by hand:
f = {1, nil, 10}
table.setn(f, 3)
table.foreachi(f, print)
Or you will need use pairs instead:
f = {1, nil, 10}
for k, v in pairs(f) do print(v) end
Milano
From: Daniel Silverstone <dsilvers@digital-scurf.org>
Reply-To: lua-l@tecgraf.puc-rio.br
To: Multiple recipients of list <lua-l@tecgraf.puc-rio.br>
Subject: Sparse numeric arrays in lua 5
Date: Sat, 29 Mar 2003 22:20:13 +0000
Hi,
I'm trying to implement a sparse numeric array in lua 5.
however given:
f = { 1, nil, 10 }
in lua 4, foreachi(f,print) will give:
1 1
2 nil
3 10
in lua 5, table.foreachi(f,print) gives:
1 1
(I.E. it stops at the nil)
Is there a known way to get around this?
D.
--
Daniel Silverstone
http://www.digital-scurf.org/
Hostmaster, Webmaster, and Chief Code Wibbler Digital-Scurf
Unlimited
GPG Public key available from keyring.debian.org KeyId:
20687895
Your business will go through a period of considerable expansion.
_________________________________________________________________
MSN Hotmail, o maior webmail do Brasil. http://www.hotmail.com