lua-users home
lua-l archive

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


On Tue, Sep 5, 2017 at 4:02 PM, Shmuel Zeigerman <shmuz@013net.net> wrote:
> With this logic we would have an infinite loop in the following case as well:
>     for k in (""):gmatch(".*") do print("-",k) end
> But we don't.

Well, it's a bit more complicated than that because a gmatch iterator
will only let you step forward through the string, but a file object
will let you "rewind" or jump around arbitrarily with the :seek()
method. So, having that extra bit of state in the gmatch iterator that
guards against reading the empty string more than once does not add
the same kind of complexity that it would for the file object.

-Duncan