lua-users home
lua-l archive

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


> It looks like while file.lines perhaps does not close the file, it
> does not seek it back to beginning. Furthermore, it looks like all
> iterators to the same file do use the same file position pointer.

It is just like reading the lines of a file. When you read up to the last
line, you reach the end of the file. That neither closes the file nor
seeks it back.

What may be confusing is that we use "file" for "file handle" (or
"stream" in C, even though they are denoted by FILE*.)  All iterators
to the same file handle use the same file handle and therefore share
the file position (which is an attribute of the handle, not of the
file).

If you create an iterator to the same file but with a different file
handle (e.g., calling 'fopen' again) it will have its own file position.

-- Roberto