[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Reading from an empty file
- From: Dirk Laurie <dirk.laurie@...>
- Date: Wed, 6 Sep 2017 07:33:28 +0200
2017-09-06 7:18 GMT+02:00 Gé Weijers <firstname.lastname@example.org>:
> On Tue, Sep 5, 2017 at 9:29 PM, Oliver Kroth <email@example.com> wrote:
>> If you have a single \n in your file. the first fp:read("*l") will return
>> "", the second fp:read("*l") will return nil.
>> f you read from a file that contains some characters but no \n, you get
>> So you get a non-nil for all \n-terminated lines.
>> and a nil for the rest, even if it contains some characters.
> That's not what I am seeing on Lua 5.3.4 (macOS). If there's anything after
> the last \n it gets returned as a separate line.
> Emacs by default does not append a \n at the end of the file, unless you
> explicitly add it, so files not ending in \n are easy to create.
file:lines() and file:read"l" are supposed to do the right thing on all
systems of your text file is in that system's format.
A Windows text file read on Linux usually has \r at the end which
is not removed by those two routines.