lua-users home
lua-l archive

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


Am 29.01.2016 um 07:34 schröbte Dirk Laurie:
I'm developing a Lua program under Linux that may in some
not totally unforeseeable future need to run under Windows.

Do line endings get standardized when Lua reads a text file?

More precisely, in the following code snippet, will "line"
contain "\r" characters?

If your program reads a Windows-formatted text file under Linux, then yes, there will be "\r" characters. The other combinations won't have "\r" characters.


infile = io.open"filename.txt"
source = infile:read"*a"
for line in source:gmatch"[^\n]+" do
    -- whatever
end


Philipp