示例工程 16-call-and-tostring

16-call-and-tostring/03-close-attribute/README.md

markdown · 0.6 KB

# 03 · close-attribute
 
**演示**:`<close>` 变量在离开 `do` 块时调用 `__close`。
**运行时**:`lua54`(5.4 特性)。
**运行**:
 
```sh
.tools/bin/lua54 scripts/run-example.lua examples/16-call-and-tostring/03-close-attribute
.tools/bin/lua54 scripts/test-example.lua examples/16-call-and-tostring/03-close-attribute
```
 
**预期输出**(lua 5.4.9 / macOS arm64):
 
```text
closed
closed=true
```
 
**看点**:清理按声明逆序执行;错误路径也会触发。
**注意**:`<close>` 值必须有 `__close`;`nil`/`false` 被忽略。