This content has been machine translated dynamically.
Dieser Inhalt ist eine maschinelle Übersetzung, die dynamisch erstellt wurde. (Haftungsausschluss)
Cet article a été traduit automatiquement de manière dynamique. (Clause de non responsabilité)
Este artículo lo ha traducido una máquina de forma dinámica. (Aviso legal)
此内容已动态机器翻译。 放弃
このコンテンツは動的に機械翻訳されています。免責事項
This content has been machine translated dynamically.
This content has been machine translated dynamically.
This content has been machine translated dynamically.
This article has been machine translated.
Dieser Artikel wurde maschinell übersetzt. (Haftungsausschluss)
Ce article a été traduit automatiquement. (Clause de non responsabilité)
Este artículo ha sido traducido automáticamente. (Aviso legal)
この記事は機械翻訳されています.免責事項
이 기사는 기계 번역되었습니다.
Este artigo foi traduzido automaticamente.
这篇文章已经过机器翻译.放弃
Translation failed!
表达式
表达式根据变量值和文字值计算值。
- 算术运算
- 关系操作
- 逻辑操作
- 连接
- 长度
- 优先级
算术运算
对数值执行算术运算。如果在算术运算中使用字符串值,则将其转换为数字 — 如果失败,则返回错误。
a + b | 添加 a 和 b |
a-b | 从 a 中减去 b |
a * b | 乘以 a 和 b |
a/b | 将 a 除以 b |
a% b | modulo = a - math.floor(a/b)*b |
a ^ b | 将 a 提高到 b 功率; b 可以是任意数字 |
-a | 否定一个 |
关系操作
关系运算比较两个值,如果关系满足,则返回 true;如果不满足,则返回 false。关系操作可以在任何类型的值之间执行。如果这些值不是相同的类型,则返回 false。数字以通常的方式进行比较。使用当前区域设置的排序序列对字符串进行比较。
a | a 等于 b |
a 〜 = b | a 不等于 b |
a < b | a 小于 b |
a > b | a 大于 b |
a <= b | a 小于或等于 b |
a >= b | a 大于或等于 b |
逻辑操作
逻辑操作传统上是在布尔值上执行的,但在这种语言中,它们可以在任意两个值上执行。nil 和 false 被认为是假的,任何其他值都被认为是真的。逻辑运算使用短距求值,其中如果第一个值确定操作的结果,则不评估第二个值。
a 和 b | 如果 a 是假或零,则返回其他返回 b |
a 或 b | 如果 a 不是假的,不是零,那么返回一个其他返回 b |
不是 | 如果 a 不是假或零返回 false,否则返回 true |
和和或操作可用于表达式中的条件评估:
a 或 b | 如果 a 未初始化(nil),则可用于提供默认值 b。这对于函数中的可选参数非常有用。 |
a 和 b 或 c | 可以用来根据条件 a 选择非零 b 或 c。如果 a 为 true,那么 a 和 b 返回 b,b 或 c 返回 b,如果 a 为假,那么 a 和 b 返回假和 false,或 c 返回 c。这相当于一个? b:c 在 C 编程语言。 |
连接
字符串连接是 s1.. s2。这会创建一个足够大的新字符串以容纳 s1 和 s2 的内容,并将内容复制到新字符串中。如果 s1 或 s2 不是字符串,则会出现错误。请注意,重复连接可能会有相当大的复制开销。如果您通过一次连接一个字节来构建 n 个字节的字符串,这将复制 n*(n+1)/2 个字节。为了获得更好的性能,您可以将一个字符串的片段连接到一个表中(稍后讨论),然后使用 table.concat()函数。这方面的一个示例显示在组合标题 () 示例中。
长度
字符串 s 的长度由 #s 返回。# 运算符也与数组表一起使用,如下文所述。
优先级
运算符优先级决定在表达式中执行操作的顺序,优先级较高的操作先于优先级较低的操作。优先顺序可以像往常一样被括号覆盖。例如,在a + b \* c
, * 的优先级高于 +,因此表达式评估为a + (b \* c)
。
最高 | ^ |
- | 不是 #-(一元) |
- | * / % |
- | .. |
- | = ~= < > <= >= |
- | 和 |
最低 | 或 |
具有相同优先级的操作从左到右(左关联)执行,但是从右到左执行的 ^ 和.. 除外(右关联)。所以一个 ^ b ^ c 被评估为 ^(b^ c)。
This Preview product documentation is Citrix Confidential.
You agree to hold this documentation confidential pursuant to the terms of your Citrix Beta/Tech Preview Agreement.
The development, release and timing of any features or functionality described in the Preview documentation remains at our sole discretion and are subject to change without notice or consultation.
The documentation is for informational purposes only and is not a commitment, promise or legal obligation to deliver any material, code or functionality and should not be relied upon in making Citrix product purchase decisions.
If you do not agree, select Do Not Agree to exit.