# 系统函数

## 功能

系统函数是 BT 运行时的全局基础能力，覆盖环境自省、动态调用、类型转换、JSON 序列化、正则、路径、休眠和随机数。

## API 列表

| API | 说明 |
| ------ | ------ |
| [envs](/docs/system/envs) | 读取系统环境对象，或按名称读取系统函数、标准库构造函数、系统常量。 |
| [env](/docs/system/env) | 读取用户全局环境对象，或按名称读取用户全局变量。 |
| [has_envs](/docs/system/has_envs) | 判断系统环境中是否存在指定名称。 |
| [has_env](/docs/system/has_env) | 判断用户全局环境中是否存在指定变量。 |
| [pause](/docs/system/pause) | 向控制台输出可选提示并等待用户按回车。 |
| [assert](/docs/system/assert) | 断言条件成立，失败时抛出运行时错误。 |
| [echo](/docs/system/echo) | 把所有参数转为字符串，用空格连接后输出到控制台。 |
| [bool](/docs/system/bool) | 把值按 BT 真值规则转换为布尔值。 |
| [eval](/docs/system/eval) | 编译并执行字符串脚本，返回脚本显式 return 或 exit 的值。 |
| [exit](/docs/system/exit) | 设置退出值并结束当前脚本执行。 |
| [include](/docs/system/include) | 运行期引入并执行 BT 文件，返回被引入文件显式 return 或 exit 的值。 |
| [include_once](/docs/system/include_once) | 运行期引入并执行 BT 文件，同一执行上下文内同一真实文件只执行一次。 |
| [cur_dir](/docs/system/cur_dir) | 返回当前源码文件所在目录。 |
| [cur_file](/docs/system/cur_file) | 返回当前源码文件路径。 |
| [cur_root](/docs/system/cur_root) | 返回当前 VM 项目根目录。 |
| [type](/docs/system/type) | 返回值的脚本可见类型名。 |
| [call](/docs/system/call) | 按函数名或函数值动态调用函数。 |
| [number](/docs/system/number) | 把值转换为数字。 |
| [string](/docs/system/string) | 把值转换为字符串。 |
| [float](/docs/system/float) | 把值转换为浮点数。 |
| [int](/docs/system/int) | 把值转换为整数。 |
| [array](/docs/system/array) | 把值转换为数组。 |
| [object](/docs/system/object) | 把值转换为对象。 |
| [json](/docs/system/json) | 把值序列化为标准 JSON 字符串。 |
| [regex](/docs/system/regex) | 编译正则表达式并返回 Regex 对象。 |
| [is_empty](/docs/system/is_empty) | 判断值是否为空。 |
| [is_null](/docs/system/is_null) | 判断值是否为 Null。 |
| [sleep](/docs/system/sleep) | 让当前线程休眠指定毫秒数。 |
| [rand](/docs/system/rand) | 生成伪随机数。 |

## 示例

```bt
result = type(json({name: 'BT'}))

// 输出：String
print result
```

## 注意事项

- 系统函数无状态；对象型标准库入口如 fs、mysql、reqwest 由 VM 的库构造分支创建。
- `print` 和 `println` 是语言输出语句，不是可通过 `call()` 动态调用的系统函数；它们的用法见 [输出](/docs/output)。
- `echo` 是系统函数，支持 `echo(value)` 和单参数无括号语法。
