https://www.lua.org/manual/5.3/manual.html#pdf-string.format
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.
[
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