lua-users home
lua-l archive

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

On Fri, Jan 29, 2016 at 2:15 AM, Dirk Laurie <> wrote:
> No, what I mean is: if it reads a Windows-formatted text file
> under _Windows_ in one go, with "*a", do the two-character line
> endings get converted into one-character line endings?
> (I know that the portable way is "lines", I'm just wondering
> how portable :read"*a" is.)

Interactive session on Windows 10:

Lua 5.3.2  Copyright (C) 1994-2015, PUC-Rio
>>>'test.txt', 'wb'):write('testing\r\nline 2\r\nEOF'):close()
>>> f ='test.txt', 'rb')
>>> f:read('a'):match('()\r\n')
>>> f:close()
>>> f ='test.txt', 'r')
>>> f:read('a'):match('()\r\n')
>>> f:close()

So the answer is yes if opened in text mode, no if opened in binary mode.

(Also, the leading "*" is no longer needed in Lua 5.3. It's still
accepted for backwards compatibility, though.)