lua-users home
lua-l archive

Re: Feature proposal: \x## notation in strings

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


On Wed, Mar 11, 2009 at 12:47 AM, Joseph Stewart
<joseph.stewart@gmail.com> wrote:
> Just a casual observation that tables rather than strings might be the
> "right" place to carry around the hex until shortly before converting into a
> string.
> If you're doing protocol work, I'd highly recommend linking in Roberto's
> struct library and represent your hex values in standard 0x## format.
> After all wouldn't you like to look at something like:
> x = struct.pack("Bc0", string.len(s), s)
> rather than:
> x = "\x05hello\x00"
String length is usually a dynamic value, therefore it is not very
useful to hardcode it as a hex value into a string literal.
Also your solution involves at least two function calls and four table
lookups (okay, it may be optimized a bit), whereas string literal
solution is virtually free -- as it is done by parser.
Alexander.

AltStyle によって変換されたページ (->オリジナル) /