lua-users home
lua-l archive

Re: Lua 5.2 Length Operator and tables (bug?)

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


On 2012-Apr-17 (Tue) at 11:18 (-0500), Coda Highland wrote:
>> function table.issequence(t)
>> for i = 1, #t do
>> if t[i] == nil then return false end
>> end
>> return true
>> end
Counterexample:
 $ cat test.lua
 function issequence(t)
 for i = 1, #t do 
 if t[i] == nil then return false end
 end
 return true
 end
 t = { 1, 2 }
 t[ 2 ] = nil
 t[ 3 ] = 3
 print( t[ 1 ], t[ 2 ], t[ 3 ], issequence( t ) )
 $ lua -v test.lua
 Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
 1 nil 3 true
Joseph
------------------------------------------------------------------------
Joseph Manning / Computer Science / UCC Cork Ireland / manning@cs.ucc.ie
------------------------------------------------------------------------

AltStyle によって変換されたページ (->オリジナル) /