示例工程 19-modules-and-env

19-modules-and-env/02-custom-package-path/README.md

markdown · 0.6 KB

# 02 · custom-package-path
 
**演示**:临时把当前目录加入 `package.path`,`require("greet")`,再恢复。
**运行时**:`lua54`、`luajit`。
**运行**:
 
```sh
.tools/bin/lua54 scripts/run-example.lua examples/19-modules-and-env/02-custom-package-path
.tools/bin/lua54 scripts/test-example.lua examples/19-modules-and-env/02-custom-package-path
```
 
**预期输出**(lua 5.4.9 / macOS arm64):
 
```text
message=hello Ada restored=true
```
 
**看点**:`?` 被模块名替换;路径顺序决定优先级。
**注意**:修改全局路径要及时恢复,避免影响其它模块。