The closest equivalent will be the %qoption string.format.
The option qformats the string between double quotes, using escape sequences when necessary, to ensure that the Lua interpreter reads securely. For example, a call
string.format('%q', 'a string with "quotes" and \n new line')
can output a line:
"a string with \"quotes\" and \
new line"
You will notice that newlines are not converted to a couple of characters \n. If you prefer this, try the following function:
function repr(str)
return string.format("%q", str):gsub("\\\n", "\\n")
end
source
share