Lua 中 or 规则

你猜 notice 是true 还是false

local notice = false

notice = notice or true

print(notice)

Lua 中 or 规则:左边为假值,就返回右边;左边为真值,直接返回左边。

Lua 假值只有两个:false、nil,其余全是真值。

local notice = false -- notice = false(假值)

notice = notice or true -- 左边是 false,所以取右边 true

print(notice) -- 输出 true

三元

local notice = false

notice = notice == nil and true or notice

print(notice) -- false

local notice2 = nil

notice2 = notice2 == nil and true or notice2

print(notice2) -- true

相关推荐
吴声子夜歌7 天前
Redis 3.x——事务与Lua
redis·lua
豆瓣鸡9 天前
Redis Lua 脚本——把多条命令打包成一个原子操作
java·redis·lua
橙色阳光五月天11 天前
MATLAB函数如何打包成独立EXE
开发语言·matlab·lua
耀耀_很无聊14 天前
12_Redis Lua 脚本踩坑:为什么 tonumber(ARGV[x]) 会得到 nil?
java·redis·lua
章老师说15 天前
NGINX官方谈Lua风险:这其实是两条网关技术路线之争
运维·nginx·负载均衡·lua·openresty
会周易的程序员16 天前
使用 LuaBridge 封装 C++ 日志库 microLog 为 Lua 模块
c++·物联网·junit·lua·日志·iot·aiot
欢呼的太阳17 天前
在上一篇随笔中介绍了四种编程语言。这次再介绍四种编程语言:Fortran、Lua、Lisp 和 Logo。
junit·lua·lisp
星空露珠18 天前
迷你世界UGc3.0脚本Wiki[剧情动画模块管理接口 Timeline]
开发语言·数据结构·算法·游戏·lua
开开心心_Every18 天前
带OCR识别的电子发票打印工具
运维·自动化·ocr·电脑·powerpoint·音视频·lua
xingpanvip1 个月前
星盘接口开发文档:本命盘接口指南
android·开发语言·css·php·lua