lua-users home
lua-l archive

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


I would have to agree, the \newline behavior is definitely surprising
to me and not intuitive. I would expect that \newline is completely
ignored, and \n is the only way to represent a newline.

On Wed, Jul 2, 2014 at 12:56 PM, Coda Highland <chighland@gmail.com> wrote:
> On Wed, Jul 2, 2014 at 10:45 AM, Paige DePol <lual@serfnet.org> wrote:
>> On Jul 2, 2014, at 12:18 PM, Paige DePol <lual@serfnet.org> wrote:
>>
>>> I am then left wondering what the escaped literal newline is used for? When quoting strings why wouldn't we want a newline to show up as '\n' instead of a backslash and a literal newline character? As this is existing functionality I will not change it, though I still wonder what it is used for, or if it something that is actually needed?
>>
>> Guess I should of thought of this issue for longer before posting...
>>
>> It is used for creating multi-line strings without using the [[ ... ]] syntax:
>>
>> Lua 5.3.0 (work3)  Copyright (C) 1994-2014 Lua.org, PUC-Rio
>>> longstring = "this is a \
>>>> long string with \
>>>> escaped newlines"
>>>
>>> print(longstring)
>> this is a
>> long string with
>> escaped newlines
>>
>> Though, to be honest, my expectation of creating a string in this fashion would of been to have a single string without newlines, just "this is a long string with escaped newlines".
>>
>> Ah well, sorry for the noise! :)
>
> My expectations match yours in that regard -- this is the behavior of
> C and C++ (though not inside strings); a backslashed newline is
> removed from the token stream entirely.
>
> /s/ Adam
>