include
include
功能
运行期引入并执行 BT 文件,返回被引入文件显式 return 或 exit 的值。
语法
include(path) include path
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| path | String | 是 | 无 | 要引入的 BT 文件路径。 |
返回值
| 类型 | 说明 |
|---|---|
| Any/Empty | include 文件执行到 return 或 exit 时返回对应值;普通执行结束返回 Empty。 |
示例
fs('include-demo.bt').write('return 7') result = include('include-demo.bt') // 输出:7 print result include 'include-demo.bt'
注意事项
- 路径按当前源码目录和项目根规则解析。
- include 文件会被编译缓存,但每次调用都会执行目标文件。
- 函数声明会进入当前 VM 全局环境。
- 无括号语法只支持语句形式;需要把返回值赋给变量时请使用
include(path)。