[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Literal string strangeness
- From: Jerome Vuarand <jerome.vuarand@...>
- Date: Fri, 23 Oct 2009 12:46:28 +0200
2009/10/23 Chris de Villiers <chrisdevilliers@gmail.com>:
> I am struggling with the long format for specifying literal strings in
> programs. Here is my program:
>
> ------------------------------------
> s = [[a
> bc]]
>
> print(string.byte(s, 1, string.len(s)))
> ------------------------------------
>
> Unfortunately I am loosing a carriage return in the string. Here is a
> hexdump of the code to clarify:
>
> 7320 3d20 5b5b 610a 620d 635d 5d0a 0a70 s = [[a.b.c]]..p
> 7269 6e74 2873 7472 696e 672e 6279 7465 rint(string.byte
> 2873 2c20 312c 2073 7472 696e 672e 6c65 (s, 1, string.le
> 6e28 7329 2929 0a0a n(s)))..
>
> You will notice there is a newline between the "a" and "b", and a
> carriage return between the "b" and "c". Here is the output as
> interpreted by the standard Lua interpreter:
>
> 97 10 98 10 99
>
> I would have expected a 13 in place of the second 10. Any ideas?
> I am using Lua 5.1.4 on linux. Thanx!
I don't know what exactly happens, but here is a test I did (on
Windows, but I think OS is irrelevant) :
s = "a\nb\rc"
print(string.byte(s, 1, string.len(s)))
> 97 10 98 13 99
loadstring("s = [[a\nb\rc]]")()
print(string.byte(s, 1, string.len(s)))
> 97 10 98 10 99
It seems the compiler doesn't preserve end of lines in long strings,
but rather force them to \n.