What is the difference between the various ways to quote strings?

There is no difference between single and double quoted strings, you may use either, although it's a good practice to be consistent. For example, people use single-quotes for internal strings and double-quotes for strings that are meant to be seen by the user/system.

These strings may contain C-style escape characters (like \n) although note that \012 is the decimal constant 12! Long string quotes [[..]] do not interpret these escapes specially. As a convenience, the first line end is ignored in cases like this:

s = [[
A string with a single line end
]]

The price of this simplicity is that expressions such as T[A[i]] are not captured properly, so Lua allows for [=[...]=] where a matching number of = characters can be used. (This is the same scheme used with long comments, with a prefixed --.) Note that under Lua 5.0 nested [[..]] was allowed, but this has been deprecated.

Due to line-end processing these long string literals are not suitable for embedding binary data directly in programs.



Back