lua-users home
lua-l archive

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


This is just the way it happens to be implemented in PUC Lua 5.4 (see
the read_line method in liolib.c) and LuaJIT (io_file_readline in
lib_io.c): It only looks for LF or EOF. You can just trim the CR though.
This also allows you to deal with Unix line endings on Windows systems.
And you get to decide whether you want to allow CRLF (bonus: what about
mixed LF & CRLF?).

On 24.03.22 14:50, Thijs Schreijer wrote:
With 'file:read’ the description of the “l” (or “*l” in previous
editions) reads:

  - "l": reads the next line skipping the end of line

When testing this on Windows and Mac, it turns out only an LF (char
10) is recognised as a line end.

This means that reading a Windows based text file, with CRLF as
line endings, the returned lines will have a trailing CR (char 13).

My expectations were that it would in all cases treat CRLF and LF
The same way, similar to the way the Lua source code can be read.

Sample code to show the behaviour:
https://github.com/lunarmodules/luasocket/pull/294#issuecomment-1077264055

Is there a specific reason for this behaviour? Did I misinterpret something?

regards
Thijs