lua-users home
lua-l archive

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


On Thu, Feb 25, 2010 at 3:52 PM, Roberto Ierusalimschy wrote:
>  loadin(env, io.lines(filename))
> (except that this does not work, because 'io.lines' cut the newlines
> from the file; we intend to fix that somehow...)

I once had to reimplement io.lines to include the line ending chars
('\r' and/or '\n'). [1]  This was for a patch tool that needed to
detect when different style line endings were fed to it, where the
file is opened in binary mode.

io.lines has similarities to string.split [2], particularly when
expressed in iterator form, and that in turn may complement
string.gmatch [3].

[1] http://lua-users.org/wiki/EnhancedFileLines
[2] http://lua-users.org/lists/lua-l/2006-12/msg00414.html
[3] http://lua-users.org/lists/lua-l/2010-01/msg01247.html