Re: Learning Lua.
Posted: September 28th, 2017, 1:34 pm
The [[ and ]] characters are mostly used in a string to help solve problems with embedded literal " (quote) and ' (single quote) characters. It's called a "long bracket" and can solve a problem like:
myString = 'This string has 'single quotes' in it'
That is an issue, as the embedded single quotes will confuse things.
You can:
myString='This string has \'single quotes\' in it'
But that can be cumbersome with a long string.
So instead you can:
myString=[[This string has 'single quotes' in it]]
The [[ and ]] are seen as a special kind of quote for the string. The sequence was chosen as you are somewhat unlikely to have [[ or ]] in a literal string, while needing quotes or single quotes is certainly possible.
You can deal with embedded [[ or ]], but that just gets more involved than I think is useful here. You won't use this much if at all.
myString = 'This string has 'single quotes' in it'
That is an issue, as the embedded single quotes will confuse things.
You can:
myString='This string has \'single quotes\' in it'
But that can be cumbersome with a long string.
So instead you can:
myString=[[This string has 'single quotes' in it]]
The [[ and ]] are seen as a special kind of quote for the string. The sequence was chosen as you are somewhat unlikely to have [[ or ]] in a literal string, while needing quotes or single quotes is certainly possible.
You can deal with embedded [[ or ]], but that just gets more involved than I think is useful here. You won't use this much if at all.