懂lua的进;n=type(c)=="string"and c or SendChatMessage(n)

来源:百度知道 编辑:UC知道 时间:2024/06/19 00:30:01
n=type(c)=="string"and c or SendChatMessage(n)
应该怎么解读?

如果 type(c) == "string", 第一个and的结果就是c, 而c因为是个string,不是nil, 所以or的结果还是c

如果 type(c) 不等与 "string", 第一个and的结果就是 nil 所以or的结果就是 SendChatMessage(n)的运行结果

lua里 exp1 and exp2 or exp3 行为差不多等同于c里的 exp1 ? exp2 : exp3