lua-users home
lua-l archive

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


On Sat, 2011-07-09 at 12:00 +0800, tsuui wrote:
> I mean, '%q' is an very useful tools,  because string tricks are so
> important for lua programmers, but it never just a tool that making
> things with good looking.
> It's more useful and powerful and should be a tool for un-escaping
> escapable chars (I think) other than for printing.  "\<newline>" just
> always screwed things up anyway.

If you are not satisfied with the behavior of %q, you can always create
a function that quotes strings the way you want. %q serves a specific
purpose - to quote arbitrary strings in a safe way, so that they could
be loaded later by Lua. It's not meant (primarily) as way to provide
"nice" output to users.

Don't expect any hand-holding from Lua. Quoting PIL: Lua gives you the
power; you build the mechanisms. If you want a function to output a
"nice" string for the users, write it yourself. In addition, the
resulting code will be more readable, because IMO the following code:

print(quote(str))

is easier to understand than:

print(string.format("%q", str))