lua-users home
lua-l archive

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

> > You can use '\0', but there is a problem if the next element is a digit.
> > "\0007" is '\0' followed by '7', but "\07" is something different. You
> > can avoid this problem with a frontier pattern:
> >
> >  output:write ((string.gsub (string.format ("bootstrap_image = %q",
> >  binary), "\\000%f[%D]", "\0")))
> You meant of course this (2 backslashes before last zero character):
> output:write ((string.gsub (string.format ("bootstrap_image = %q",
> binary), "\\000%f[%D]", "\\0")))
> Thanks for the tip, anyway))
> But I meant what I wrote: putting zero byte like string.byte (0), not
> putting backslash and zero character.

Sorry for my misunderstanding.

> Again, it works fine for me but will it work everywhere? I couldn't
> find an answer in manual or the list.

>From the Lua part it should work everywhere, but I am not sure whether
all file systems will be happy with embedded zeros inside text files.

> > (Anyway note that, as Rapin pointed out, there may be more efficient
> > ways to store your data.)
> How exactly?

For instance, you may represent other "control" bytes as themselves, as
you intended to do with \0. As long as Lua is concerned, any byte inside
a double-quoted string that is different from escape '\', double quote
'"', and new lines (both '\r' and '\n') is OK.  As with '\0', you just
have to worry about the file system.

-- Roberto