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 <dirk.laurie@gmail.com> 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 Lua.org, PUC-Rio
>>> io.open('test.txt', 'wb'):write('testing\r\nline 2\r\nEOF'):close()
true
>>> f = io.open('test.txt', 'rb')
>>> f:read('a'):match('()\r\n')
8
>>> f:close()
true
>>> f = io.open('test.txt', 'r')
>>> f:read('a'):match('()\r\n')
nil
>>> f:close()
true

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.)