lua-users home
lua-l archive

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

* On 2009-03-10 Luiz Henrique de Figueiredo <> wrote  :

> > There's probably a good reason why this is not already part of lua, can
> > anybody shed some light on this ?
> To avoid bloat and also because the perfect place for such a feature is
> in a text-encoding library (which would also handle base64, ascii85, etc.)

I think the HEX notation differs from the others in your list in that it
is not ment as an encoding type, but just to mix in binary characters in
strings. Lua alread provides the decimal form, and I guess that the hex
form \xNN can be added to the lua core in no more then 10 lines of C
somewhere in llex.c:read_string().

> Also, it is trivial to write it in Lua:
> local XT={}
> for c=0,255 do
> 	XT[string.format("%02X",c)]=string.char(c)
> 	XT[string.format("%02x",c)]=string.char(c)
> end
> function X(s)
> 	return (string.gsub(s,"(..)",XT))
> end
> print(X"4c75612e6f7267")

True, but then again, there's almost nothing that can be trivially
written in lua :)

Your example differs from my original proposal, which is to add the
escape sequence to regular strings so that a string can contain both
normal text and hex bytes, like "text\0x3text"