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

相关推荐
Flynn Liang3 天前
Agent 生产级可靠性与风控:Lua 原子性、Token 预算与持久化边界
人工智能·redis·lua·agent·token·ai agent
开开心心就好6 天前
显示器关不掉怎么办,用小工具一键息屏
算法·智能手机·pdf·计算机外设·ocr·lua·1024程序员节
不绝1916 天前
Lua基础语法入门:注释、变量类型与字符串操作
开发语言·lua
码客-ygluu10 天前
X3 LUA 异步分布式微服务集群框架
c++·架构·lua
寂寞的船11 天前
【Unity知识速递】第13期 Unity 内存泄漏排查实战:从 Memory Profiler 到 Lua 引用泄漏的生产级全链路诊断
unity·junit·c#·游戏引擎·lua
努力努力再努力wz14 天前
【Lua 进阶系列】从 C++ 对象到 Lua 变量:一文理解 userdata、Lua 栈与元表绑定机制
c++·junit·lua
阿卡好可爱15 天前
Lua 热更新不生效:改完文件线上仍是旧逻辑,package.loaded 与 upvalue 重绑定详解
数据结构·分布式·后端·架构·lua
Joy T15 天前
Redis Lua 原子限流:Lua 脚本、竞态条件与并发控制
数据库·redis·lua·限流·竞态条件·redis scripting