Documentation Index
Fetch the complete documentation index at: https://fluxon.tabooproject.org/llms.txt
Use this file to discover all available pages before exploring further.
系统函数由 FunctionSystem 提供,直接按名称调用,无需命名空间。
输出与错误
| 函数 | 签名 | 说明 |
|---|
print | print(value) | 向标准输出打印一行文本,末尾自动换行。 |
error | error(value) | 向标准错误流打印一行文本,末尾自动换行。 |
示例:
print("Hello Fluxon") # => 在控制台打印 Hello Fluxon\n
error("something wrong") # => 在错误输出打印一行信息
睡眠与阻塞
| 函数 | 签名 | 说明 |
|---|
sleep | sleep(ms) | 让当前线程睡眠指定毫秒数,期间会阻塞当前脚本执行。 |
示例:
print("before")
sleep(1000) # 约 1 秒
print("after")
反射与动态调用
| 函数 | 签名 | 说明 |
|---|
forName | forName(className) | 加载指定的宿主类并返回对应 Class 对象。 |
call | call(func) / call(func, args) | 调用运行时函数或已获取的函数对象,可选以数组形式传入参数列表。 |
如需在脚本中直接构造对象或访问静态成员,可使用
new /
static(需启用特性),见
Java 互操作。
示例:
# 通过名称调用已注册函数
call("print", ["hello from call"]) # 等价于 print("hello from call")
运行时环境
| 函数 | 签名 | 说明 |
|---|
this | this() | 返回当前环境的目标对象(target),即 :: 上下文调用的左侧值。 |
env | env() | 返回当前环境对象(Environment),可用于高级运行时操作。 |
# this() 在上下文调用中获取目标对象
"hello" :: {
target = this() # => "hello"
print(&target)
}
# env() 获取当前环境
currentEnv = env()
环境扩展方法
通过 env() 获取的环境对象支持以下扩展方法:
| 方法 | 说明 |
|---|
env()::localVariables() | 返回当前作用域的所有局部变量值(数组)。 |
env()::localVariableNames() | 返回当前作用域的所有局部变量名(数组)。 |
x = 1
y = 2
names = env() :: localVariableNames() # => ["x", "y", ...]
values = env() :: localVariables() # => [1, 2, ...]
抛出异常
| 函数 | 签名 | 说明 |
|---|
throw | throw(error) | 直接抛出一个错误对象或把任意值包装为运行时异常抛出。 |
if &x < 0 {
throw("x must be non-negative")
}
相关链接