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

相关推荐
MC皮蛋侠客1 天前
Redis 系列(七):事务、Pipeline 与 Lua 脚本——从原子性到 Functions
数据库·redis·lua
l1t4 天前
用李红艳先生的DuckDB luajit插件批量计算数独
数据库·sql·lua·duckdb
智购科技自动售卖机厂家7 天前
从STM32到RK3588——自动售货机嵌入式主控方案的架构演进~YH
stm32·嵌入式硬件·物联网·架构·lua·零售·symfony
qq_370773099 天前
Unity游戏xLua逆向实战:从SO版本识别到Lua脚本热替换全链路
游戏·unity·lua
星空露珠12 天前
迷你世界3.0API,事件监听
开发语言·数据结构·数据库·游戏·lua
ellis197014 天前
u3d插件xLua[二]例2:U3DScripting,例3:UIEvent分析
unity·lua
寒水馨15 天前
Windows下载、安装neovim-v0.12.4(附安装包nvim-win64.msi)
windows·编辑器·vim·lua·终端·lsp·neovim
烤代码的吐司君16 天前
Lua 脚本
开发语言·junit·lua
寒水馨16 天前
macOS下载、安装neovim-v0.12.4(附安装包nvim-macos-arm64.tar.gz)
macos·vim·lua·文本编辑器·终端·lsp·neovim
背书包的甜瓜17 天前
Python Excel转lua配置工具
lua