示例工程 05-variables-and-scope

05-variables-and-scope/03-multi-assign-truncation/README.md

markdown · 0.7 KB

# 03 · multi-assign-truncation
 
**演示**:右侧少于左侧补 `nil`;多重返回只在最后一个位置展开。
**运行时**:`lua54`、`luajit`。
**运行**:
 
```sh
.tools/bin/lua54 scripts/run-example.lua examples/05-variables-and-scope/03-multi-assign-truncation
.tools/bin/lua54 scripts/test-example.lua examples/05-variables-and-scope/03-multi-assign-truncation
```
 
**预期输出**(lua 5.4.9 / macOS arm64):
 
```text
a=1 b=2 c=nil
m=1 n=2
p=1 q=10
```
 
**看点**:`three(), 10` 中 `three()` 被截断为 1 个值,因为不在末尾。
**注意**:要保留全部返回值用 `table.pack` 或 `select`。
 
**luacheck 局部放行**:`c` 故意不被赋值,用来演示补 nil。