lua-users home
lua-l archive

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


2017-09-06 7:18 GMT+02:00 Gé Weijers <ge@weijers.org>:
>
> On Tue, Sep 5, 2017 at 9:29 PM, Oliver Kroth <oliver.kroth@nec-i.de> 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
>> nil.
>> 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.