lua-users home
lua-l archive

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


Hi,

On Thu, 24 Mar 2022 13:50:50 +0000
Thijs Schreijer <thijs@thijsschreijer.nl> 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?

I don't have a Windows box to test this on, but if I recall correctly, opening the file in binary mode on Windows should allow 'l' to also trim '\r'. I could be misremembering though.

Cheers,
Mitchell