[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: System-dependent end-of-line
- From: Peng Zhicheng <pengzhicheng1986@...>
- Date: Sun, 15 Apr 2012 21:12:34 +0800
于 2012-4-15 20:45, Dirk Laurie 写道:
I'm in the unfamiliar position of having to be worried about
whether my Lua program will run properly not only on a Linux
system but on someone else's Windows or Macintosh.
The program is a text filter: it reads a text file line by line,
does something to the lines and writes it out. I do the
reading in using file:lines() which strips off end-of-line
and the writing out by
io.write(table.concat(lines,'\n'))
I suppose that "\n" should be system EOL. I don't want to
read off the input what that is; I want to write the proper EOL
for the system on which Lua is running.
From my own understanding, Lua's io library is wrapped on the standard C stream IO APIs.
so the `io.write' function behaves just like the `fwrite' function of <stdio.h>
so it depends on the underlying C runtime.
IIRC, the MS C runtime would do the EOL translation if the file is opened in `text mode'.
while the Linux C runtime treats 'text mode' just the same as 'binary mode',
in another word, Linux don't have the `text mode' in effect.
so I think you can expect the correct behavior, as long you open files in 'text mode' instead of 'binrary mode'.
but you'd better do some experiments to be sure.