lua-users home
lua-l archive

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


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