[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Testing for a sequence (was Re: Lua 5.2 Length Operator and tables (bug?)
- From: Dirk Laurie <dirk.laurie@...>
- Date: Thu, 19 Apr 2012 08:28:26 +0200
> Petite Abeille wrote:
>
> local function is_seq( aTable )
I do it this way:
function is_seq(aTable)
local count=0
local nmax=-1
for k in pairs(aTable) do
n=tonumber(k)
if n and n%1==0 and n>0 then
count=count+1; nmax=math.max(nmax,n)
end
end
return nmax==count
end
BTW, why does the definition of a proper sequence exclude {}?
The table functions and length operator work properly in that case too.