gpt4 book ai didi

lua - 如何在 Lua 函数上使用参数

转载 作者:行者123 更新时间:2023-12-02 09:27:51 24 4
gpt4 key购买 nike

我是Lua编程的初学者,我想了解以下内容:

在下面的语句中,为什么使用这些括号([])?我没有找到任何解释。

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

此外,如果函数多一个参数怎么办?会不会是这样的:

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

(我从链接中获取了这些示例:http://www.tutorialspoint.com/lua/lua_database_access.htm)

最佳答案

双方括号用于在 Lua 中指定文字字符串。这些字符串可以包含多行并将转义序列解释为纯文本。至于参数,它们的处理方式与任何其他值没有什么不同。对于具有两个参数的函数,您的示例在语法上是正确的。

当您的字符串包含可能需要手动转义的字符(例如 \'" 时,此样式是理想的选择例如,读写 [[here's a "quote"]] 比编写 "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;

关于lua - 如何在 Lua 函数上使用参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36122987/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com