Redemble Docs
v0.2 在原有命令系统之上加入了真正的语言内核:变量、表达式、分支、循环、函数、异常与列表。旧脚本保持兼容。
当前版本 0.2.0 · 45 个模块 · 717 条命令 · 86 个Examples
安装与运行
Windows 64 位,绿色免安装。Downloads后直接运行 redemble.exe 进入交互模式。
redemble run examples\90-core-hello.rd redemble run examples\94-core-args.rd alpha beta 42 redemble check examples\99-core-selftest.rd redemble --version
Downloads and run directly. No installation needed.
五分钟入门
set name "Redemble"
set year 2026
say "你好,$name"
say "明年是 ${year + 1} 年"
fn fib n
if n < 2
return n
endif
return fib(n - 1) + fib(n - 2)
endfn
set i 0
while i < 10
say "fib($i) = " + fib(i)
set i = i + 1
endwhile
变量与表达式
set 名称 值 或 名称 = 值。值类型:number、string、bool、list、null。
set a 1 + 2 * 3 # 7 set b (1 + 2) * 3 # 9 set c 2 ^ 10 # 1024 set s "a" + "b" # ab set ok 1 < 2 and not false x = x + 1 # 赋值简写
优先级:or → and → not → 比较 → + - → * / % → ^ → 一元 → 下标。真值:false / 0 / "" / 空列表 / null 为假。
分支
if score >= 90 say "A" elif score >= 60 say "B" else say "C" endif
循环
while i < 10
set i = i + 1
endwhile
repeat 3
say "第 $it 次" # it 从 1 开始
endrepeat
foreach v in [1, 2, 3]
if v == 2
continue
endif
say v
endforeach
break 跳出循环,continue 进入下一次。循环上限 500 万次,防止死循环卡死。
函数
fn add a b
return a + b
endfn
fn greet(who)
return "你好," + who
endfn
say add(1, 2)
say greet("世界")
call add 3 4 # 不关心返回值
支持递归(上限 200 层)。函数有局部作用域,可读全局变量;要修改全局先 global 名称。
异常与断言
try say 1 / 0 catch err say "捕获: $err" endtry throw "自定义错误" assert 1 + 1 == 2
运行期错误(未定义变量、类型错误、命令异常)都能被 try 捕获,错误消息带文件与行号。
列表
set xs [3, 1, 2] say xs[0] # 3,支持负数下标 push(xs, 4) say sort(xs) # [1, 2, 3, 4] say join(xs, "-") say split("a,b", ",")
内置函数
| 分类 | 函数 |
|---|---|
| 字符串 | len upper lower trim substr split join replace contains starts ends indexof chr ord |
| 数值 | abs floor ceil round sqrt pow min max random range sum |
| 类型 | str num int bool type |
| 时间 | now date time |
| 列表 | len push pop sort reverse sum join contains |
作用域
顶层变量全局可见。函数参数与 set 默认写入局部;读取时先局部后全局。要修改全局:
set total 0 fn addTotal n global total set total = total + n endfn
函数看不到其它函数的局部变量,也没有闭包。匿名函数与字典在路线图中。
命令与模块
命令用连字符连接,先导入模块:
swqa-put math math-add 12 30 swqa-put all urlresfd-get https://example.com
全部 717 条命令见 Reference(由编译器分发表自动生成)。
混写规则
一行先按语言语法解析;不是语言结构的行,原样交给命令系统。因此新老写法可以在同一个脚本里共存:
swqa-put print set name "Redemble" print 你好,$name say "1 + 2 = " + (1 + 2) math-add 1 2
say;需要命令输出时直接运行命令。语法检查与Logout码
redemble check app.rd
[check] 通过 · app.rd · 96 行
正常Logout码 0,语法/运行错误 1,exit N 返回 N,方便 CI 判断。
打包 exe
swqa-put build rd-build app.rd app.exe
预检 → 生成 IR → 打包。重新编译编译器请运行 build.cmd(编译失败不会覆盖旧 exe)。
能力状态
我们只把已经能运行的能力标为“可用”。当前边界:
- 可用:语言核心、命令系统、网络抓取、Security检测(授权目标)、文件、SQL、图形、音频、2D 游戏、打包、Python 桥。
- 部分:AI(版本/状态/USB 枚举)、调试(变量查看,无断点单步)、IDE(语法着色,无自动补全)。
- 规划:字典/闭包/静态类型、调试器、GraphQL/gRPC/WebSocket、SDL/OpenGL、摄像头/麦克风、视频编解码、跨平台。
遇到问题?在 Home留言板 反馈,或运行 redemble self-check 自检。