|
Let's see the documented example: string.format('%q', 'a string with "quotes" and \n new line') Well, if there's a new user of lua, he who doesn't really consumed the documents, maybe, he is going to believe the result string is: "a string with \"quotes\" and \n new line" probably. but, very soon, he will realize that he was sadly wrong, because lua just ate half of the '\n' - eat 'n', left '\' : "a string with \"quotes\" and \ new line" lua: hotdog? I hate the taste of sausage mixing with bread ... lol but that's ok, and the result string could be used as source string with calls like "load" and "lua_load" etc. however, under some special cases (e.g. debugging output), I usually need to print the result on a limited screen area and hope not to make mess of other outputs. so, I usually changed the lua source code to serve my need, like this: (lua 5.2b, file: "lstrlib.c", function: "addquoted") static void addquoted
(lua_State *L, luaL_Buffer *b, int arg) {
luaL_addchar(b, '"' );
while (l--) {
if (*s == '"'
|| *s == '\\' /*|| *s ==
'\n'*/ ) { // I just comment this...
luaL_addchar(b, '\\' );
luaL_addchar(b, *s);
}
else if ... } |