lua-users home
lua-l archive

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


In Lua 5.2, ipairs() on any non-table (or table-like) type would throw
an error.  In 5.3, ipairs("foo") or ipairs(nil) returns a valid iterator
function, as long as LUA_COMPAT_IPAIRS isn't turned on.  (It is turned
on by LUA_COMPAT_5_2, which is the default in the base release.)

For nil, I get something useful on iteration:

  > for i, v in ipairs(nil) do print(i, v) end
  stdin:1: bad argument #1 to 'for iterator' (table expected, got nil)
  stack traceback:
          [C]: in function 'for iterator'
          stdin:1: in main chunk
          [C]: in ?

But for a string I get, unexpectedly, nothing.

  > for i, v in ipairs("foo") do print (i, v) end
  > 

So...  Bug, or feature?  I vote bug, if for no other reason than the
inconsistent behavior.

-- 
Michael Welsh Duggan
(mwd@cert.org)