[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Feature proposal: \x## notation in strings
- From: David Manura <dm.lua@...>
- Date: Thu, 12 Mar 2009 00:05:11 -0400
On Wed, Mar 11, 2009 at 8:19 PM, Mike Pall wrote:
> 1. There is no easy way to add a meta-mechanism, because strings
> are parsed before any such mechanism could take effect.
One solution would be to define one's own escaping within an
unescaping string: X[[\x05hello\n\x00]] . Things like \n would need
to be reimplemented though. This could be useful for representing a
regex (e.g. lrexlib) that may have very different escape sequences.
> 2. Apart from the \x and \u escape sequences, there is little
> demand for other types of escape sequences which would warrant a
Multiline string break escapes (including sequences that expand to
nothing) and inline interpolation of variables into strings come
into mind. Some of this (e.g. control structures) leads to template
> 3. Lua's strings are multi-purpose because they are just sequences
> of bytes. They are often used to store non-textual content. An
> idiomatic way to enter this content as literals is missing.
However, on occasions I find X"4c75612e6f72" or even X"4c75 612e 6f72"
or "1001100..." (under a certain byte ordering) syntactically
preferable to "\x4c\x75\x61\x2e\x6f\x72", which is in turn can be
quite preferable to the decimal representation. Also, if I'm doing
protocol work, as mentioned above, it's typical to have not
"\x05hello\x00" but rather "\x05hello\xcd\x00", where "\xcd" is some
type of checksum. In that case, it's syntactically cleaner to write
X"hello", where X prepends the initiator byte and appends the checksum
That said, I would not be against Lua adding "\x" (which I too have
asked about in the past).