[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Bug in 5.3 ipairs(), or feature?
- From: "Soni L." <fakedme@...>
- Date: Wed, 04 Mar 2015 13:21:46 -0300
On 04/03/15 01:13 PM, Michael Welsh Duggan wrote:
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)
[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
The string metatable has __index which is an empty sequence.
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.