简体   繁体   中英

How to use parameters on Lua Functions

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 )

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\\'sa "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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM