lua-users home
lua-l archive

Re: [PATCH] Quoted String "%q" non-ascii escaping (w/ hex).

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




On 6/27/2017 6:56 PM, Duane Leslie wrote:
[
https://www.lua.org/manual/5.3/manual.html#pdf-string.format 

where it says "The q option formats a string between double quotes, using escape sequences when necessary to ensure that it can safely be read back by the Lua interpreter." Note that it explicitly does not mention that the result could be safely read by a C compiler.

Within string literals, Lua is already perfectly fine with UTF-8 content. It may also be fine with other extended ASCII forms, or with some other Unicode translation formats, leaving most of those details up to the system outside of Lua. But don't use UTF-7. Just don't. [
 
[
 
 
You would be far better served by writing a Lua function that generates a proper C string literal and calling that instead of depending on string.format("%q") and additional processing.

Lua is designed to work well with C. It is also designed to be used by people who don't want to know anything about C or lower level programming issues.  While the choice of base-10 for \ddd escapes is occasionally a source of friction when switching back and forth between the languages, it is no worse that the choice of 1-based array indexing and numerous other details that differ.
-- 
Ross Berteig Ross@CheshireEng.com
Cheshire Engineering Corp. http://www.CheshireEng.com/
+1 626 303 1602

AltStyle によって変換されたページ (->オリジナル) /