lua-users home
lua-l archive

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

I have a little weirdness that happens when I run a Lua
script whose end-of-lines are in DOS format on a platform
whose EOL format is Unix.  I've seen this problem alluded to
on this list, but never directly treated.  This script:

print("Line one")
Line two
Line three

gives the expected results in three cases:  (Details on what
versions of everything I'm using are below.)

- Platform and script both using Unix format:
 Line one\nLine two\nLine three\n\n

- Platform and script both using DOS format:
 Line one\r\nLine two\r\nLine three\r\n\r\n

- Platform using DOS format, script using Unix format:
 Line one\r\nLine two\r\nLine three\r\n\r\n

But if I save it in DOS format and run it under a Unix-style
platform, I get:

Line one\n\r\nLine two\r\nLine three\r\n\n

In other words, two bad things are happening.  One is that
the script EOL format is being instead of the platform EOL
format in the multiline string.  The other is that the
leading EOL in the second print statement fails to be
omitted (presumably because the interpreter doesn't
recognize it as "leading" because of the "\r").

It seems like this could be fixed without messing anything
else up by having the interpreter strip out all "\r"s (which
the Windows interpreter [or a Macintosh interpreter] would
never even see because it reads the file in text mode), but
maybe there's something deeper going on that I don't

I'm using Lua 5.0.2 compiled with gcc 3.2.2 on Red Hat Linux
release 9 (Shrike), kernel release 2.4.20-28.9.

Aaron Brown
arundelo @

FREE pop-up blocking with the new MSN Toolbar ? get it now!