[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Unexpected behaviour with %q formatted string
- From: Remo Dentato <rdentato@...>
- Date: Fri, 20 Jul 2007 22:24:14 +0000
Hi there, I just found an unexpected behaviour that, I think, should be corrected whenever a new Lua version will be released.
I'm using a lua interpreter compiled under Windows XP with Mingw (gcc 3.4.2).
If a script has a constant string that contains the character 0x1A, when I execute it I get the message "unfinished string near <eof>".
example = "abc.def" -- <-- . is actually a 0x1A character!
I guess that the read function in the gcc C library interprets 0x1A (CTRL-Z) as EOF. When the parser arrives at that points it receive and EOF and gives the error, I chased it up to luaZ_fill() before realizing that should have been the cause.
That would not be a big problem if I weren't using a string.format("%q",s) to pass data around. In this case the assumption that every string created with %q can be safely re-read by the lua interpreter is no longer true.
I can't test it on Linux or Mac at the moment but I strongly suspect that they won't have any issue. As a workaround I will replace any '0x1A' character in the string with "\032" before writing it out.
It would be nice, though, if that could be fixed in next version of Lua so that %q always works as expected. My preference would be to modify the addquoted() function in lstrlib.c so that any control character would be replaced by "\xxx", just to play safe, but any solution will be well accepted of course!
Make every IM count. Download Windows Live Messenger and join the i'm Initiative now. It's free. Make it count!