示例工程 08-table-structure

08-table-structure/02-length-border/README.md

markdown · 0.6 KB

# 02 · length-border
 
**演示**:`{1,2,nil,4}` 的 `#` 是边界(可能是 2 或 4),元素个数是 3;`ipairs` 停在洞处。
**运行时**:`lua54`、`luajit`。
**运行**:
 
```sh
.tools/bin/lua54 scripts/run-example.lua examples/08-table-structure/02-length-border
.tools/bin/lua54 scripts/test-example.lua examples/08-table-structure/02-length-border
```
 
**预期输出**(lua 5.4.9 / macOS arm64;`border` 可能随构造方式变化):
 
```text
border=4 count=3 ipairs=2
```
 
**看点**:`#` 只对序列有确定含义;洞表上不要用它当计数。
**注意**:需要准确数量用 `pairs` 计数或 `table.pack().n`。