示例工程 15-index-and-newindex

15-index-and-newindex/03-proxy-with-pairs/README.md

markdown · 0.6 KB

# 03 · proxy-with-pairs
 
**演示**:`__pairs` 返回底表的 `next`,让 `pairs(proxy)` 看到真实数据。
**运行时**:`lua54`(LuaJIT 不支持 `__pairs`,实测按普通表遍历)。
**运行**:
 
```sh
.tools/bin/lua54 scripts/run-example.lua examples/15-index-and-newindex/03-proxy-with-pairs
.tools/bin/lua54 scripts/test-example.lua examples/15-index-and-newindex/03-proxy-with-pairs
```
 
**预期输出**(lua 5.4.9 / macOS arm64):
 
```text
count=2 a=1
```
 
**看点**:没有 `__pairs` 时,代理表对 `pairs` 是空的。
**注意**:`__pairs` 是 5.2+;跨运行时需检测。