lua-users home
lua-l archive

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


It was thus said that the Great Dirk Laurie once stated:
> 2018-01-07 9:03 GMT+02:00 nobody <nobody+lua-list@afra-berlin.de>:
> >> 2018-01-07 5:01 GMT+02:00 Soni "They/Them" L. <fakedme@gmail.com>:
> >>>
> >>>
> >>> print("{\n\z
> >>>      \x20   \"hello\": \"world\"\n\z
> >>>      }")
> >>>
> > On 2018-01-07 07:48, Dirk Laurie wrote
> >>
> >> Isn't that just a tortuous way of coding something that Lua can do much
> >> more conveniently?
> >>
> >> print [[{
> >>      "hello": "world"
> >> }]]
> >
> >
> > Not if CR-LF must not be normalized (e.g. binary data or fixed format
> > like HTTP / …). Then you're forced to use "normal" strings.
> 
> This sounds so reasonable that I almost believed it until I tried to
> figure out what it means.
> 
> I suppose "normalize" has something to do with whether the actual
> bytes emitted by "\n" are "\x0a" or "\x0d" or some combination thereof.
> I do not see documented in the Lua manual whether the non-printing
> newline in a long string is rendered differently from the escape
> sequence "\n", but I will be vastly surprised if it is.

  What "\n" maps to depends upon the operating system.  Windows will map
"\n" to CRLF.  Unix will map "\n" to LF.  Pre Unix Mac OS would map "\n" to
CR, but now that it's Unix, it maps it to LF.

  The two strings:

x = "hello\n"
y = [[
hello
]]

are the same.  To get an actual answer, you will probably have to consult
your vendor's C compiler or operating system documentation.

  I think what nobody is talking about is ensuring that the end of line for
text based Internet protocols is CRLF.  That is, to request a document via
HTTP, you must send [1]:

GET /resource HTTP/1.1\r\n
Host: www.example.net\r\n
Connection: close\r\n
\r\n

  -spc

[1]	Some web servers may accept just CR or LF.  Your milage may vary.