[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: hpairs?
- From: Dirk Laurie <dpl@...>
- Date: Wed, 29 Dec 2010 06:54:29 +0200
On Tue, Dec 28, 2010 at 10:13:10PM +0200, Steve Litt wrote:
>
> #!/usr/bin/lua
>
> local arr={"one", "two", "three"}
>
> arr[4] = "four"
> arr[1.5] = "one point five"
> arr["steve"] = "Litt"
>
> for k, v in pairs(arr) do
> if type(k) ~= "number" or math.ceil(k) ~= k then
> print(k)
> print(v)
> print("")
> end
> end
>
arr={1,2,3,4,5}; arr[12345]=12345
The solutions involving doing ipairs first to create a set of keys
are the only ones for which you can immediately see that they must
work.
Thanks for this discussion: as a result, in my application I will
make sure that my non-ipairs keys are all strings.
Dirk