示例工程 27-debugging-and-observability

27-debugging-and-observability/02-getinfo-caller/README.md

markdown · 0.6 KB

# 02 · getinfo-caller
 
**演示**:`debug.getinfo(2, "nSl")` 读取调用者的名字/源/行号。
**运行时**:`lua54`、`luajit`。
**运行**:
 
```sh
.tools/bin/lua54 scripts/run-example.lua examples/27-debugging-and-observability/02-getinfo-caller
.tools/bin/lua54 scripts/test-example.lua examples/27-debugging-and-observability/02-getinfo-caller
```
 
**预期输出**(lua 5.4.9 / macOS arm64;路径随加载方式):
 
```text
location=run:20
```
 
**看点**:`name` 可能为 nil(匿名调用),要回退到 `short_src`。
**注意**:`getinfo` 有开销,别在热路径频繁调用。