lua-users home
lua-l archive

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


On Mar 12, 2014, at 7:49 PM, meino.cramer@gmx.de wrote:

> while true do
>   line = f:read("*line" )
>   if not line then break end

Ah, also… this is more idiomatically written as:

for aLine in f:lines() do
...
end

N.B.

While we are at it… there is no such format as ‘*line’ in file:read (···):

The available formats are

• "*n": reads a number; this is the only format that returns a number instead of a string.
• "*a": reads the whole file, starting at the current position. On end of file, it returns the empty string.
• "*l": reads the next line skipping the end of line, returning nil on end of file. This is the default format.
• "*L": reads the next line keeping the end of line (if present), returning nil on end of file.
• number: reads a string with up to this number of bytes, returning nil on end of file. If number is zero, it reads nothing and returns an empty string, or nil on end of file.

http://www.lua.org/manual/5.2/manual.html#pdf-file:read