2

I am a beginner in Lua programming, and I want to understand the following:

On the statement below, why it is used these brackets ([ and ])? I did not find anything explaining it.

conn:execute([[ 'MySQLSTATEMENT' ]])

Also, what if the function had one more parameter? Would it be like this:

conn:execute('another parameter',[[ 'MySQLSTATEMENT' ]]).

(I took these examples from the link: http://www.tutorialspoint.com/lua/lua_database_access.htm)

1 Answer 1

5

Double square brackets are used to specify literal strings in Lua. These strings can contain multiple lines and interpret escape sequences as plaintext. As for parameters, they are treated no differently than any other value. Your example is syntactically correct for a function with two parameters.

This style is desirable when your strings contain characters which might otherwise have to be escaped manually, such as \, ', and ". For example, it's far easier to read and write [[here's a "quote"]] than it is to write "here's a \"quote\"" or 'here\'s a "quote"'.

We can delimit literal strings also by matching double square brackets [[...]]. Literals in this bracketed form may run for several lines, may nest, and do not interpret escape sequences. Moreover, this form ignores the first character of the string when this character is a newline. This form is especially convenient for writing strings that contain program pieces;

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.