示例工程 06-control-flow-and-truthiness

06-control-flow-and-truthiness/03-and-or-returns-operand/README.md

markdown · 0.6 KB

# 03 · and-or-returns-operand
 
**演示**:`0 or "x"` 返回 `0`;`nil or "x"` 返回 `"x"`;`and` 返回最后一个真值。
**运行时**:`lua54`、`luajit`。
**运行**:
 
```sh
.tools/bin/lua54 scripts/run-example.lua examples/06-control-flow-and-truthiness/03-and-or-returns-operand
.tools/bin/lua54 scripts/test-example.lua examples/06-control-flow-and-truthiness/03-and-or-returns-operand
```
 
**预期输出**(lua 5.4.9 / macOS arm64):
 
```text
value=0
fallback=default
chained=b
```
 
**看点**:`x = x or default` 只在 nil/false 时生效,0 与空串不会被替换。
**注意**:要布尔结果用 `not not x`。