嘿,脚本开发者们!
还记得上周我介绍的那个能编译成 VBScript 的现代编程语言 Hulo 吗?这周它又有了重大更新!
🚀 本周重磅更新
1. Bash 转译器正式上线!
是的,你没看错! Hulo 现在不仅支持 VBScript ,还支持 Bash 了!
这意味着你可以用同一套现代语法,同时生成 Windows 和 Linux/macOS 的脚本:
// main.hlclass User { pub name: str pub age: num pub fn to_str() -> str { return "User(name: $name, age: $age)" } pub fn greet(other: str) { MsgBox "Hello, $other! I'm $name." }}let u = User("John", 20)MsgBox $u.to_str();$u.greet("Jane");
在文件所在的工作目录执行 hulo main.hl
命令即可得到两份转译后的文件(当然 Hulo 命令还支持其他功能,以及从 huloc.yaml 读取配置,在此就不一一列举了,可以通过 hulo -h
查看,或者查询官方文档)。
生成的 Bash 代码:
#!/bin/bashfunction create_user() { local name=$1 local age=$2 declare -A user user["name"]=$name user["age"]=$age echo "$(declare -p user)"}function user_to_str() { eval "declare -A user=${1}" echo "User(name: $name, age: $age)"}function user_greet() { eval "declare -A user=${1}" local other=$2 MsgBox "Hello, $other! I'm $name."}u=$(create_user "John" 20)MsgBox $(user_to_str $u)user_greet $u "Jane"
生成的 VBScript 代码:
Class User Public name Public age Public Function to_str() to_str = "User(name: " & name & ", age: " & age & ")" End Function Public Function greet(other) MsgBox("Hello, " & other & "! I'm " & name & ".") End FunctionEnd ClassSet u = New Useru.name = "John"u.age = 20MsgBox(u.to_str())u.greet("Jane")
至此,看起来一切正常对吗?不幸的是,在 Bash 平台上的代码是无法正常运行的,他会因为缺少 MsgBox 而报错,这是因为我们在 Hulo 代码中使用的是 MsgBox 而非 echo 。因此,如果你想让他正常运行就需要将 MsgBox 更改为 echo 在进行转译。但是,这不就和 Hulo 的跨平台宣传产生冲突了? hhh ,原因是类似 use MsgBox = If<$platform == "vbs", MsgBox, If<$platform == "powershell", Write-Host, echo>>
的语法糖还没有完工,造成了命令没法转译的割裂感。Hulo 也不想采用硬编码的方式强行把命令在转译器中做转换,由此带来了比较差的开发体验。这个特性将在未来的版本实现,请给 Hulo 以时间。
Ps. Hulo 将这个特性称之为命令体操,为了实现这个特性,Hulo 吸取了 TypeScript 类型体操的所有优点,这意味着这套系统将连带着 Omit 、Pick 、Exclude 等类型工具一同构成强大的命令系统。
2. 包管理工具 HLPM 来了!
hlpm
的核心功能就是分发第三方库,由于 import 暂时不支持模块解析,尽管 hlpm 核心功能已经开发完成,但是调用模块的运行还是不支持的。但是,你可以用其先初始化项目,并编写 hulo.pkg.yaml
和 huloc.yaml
文件控制项目的编译过程。这有点类似于 package.json
和 tsconfig.json
的作用。
# 初始化新项目hlpm init my-script# 运行脚本hlpm run test# 运行文件,等价于 hulo main.hlhlpm run main.hl
3. 交互式开发环境 Hulo-REPL
新增了 hulo-repl
命令:
- 代码补全 主题设置 实时词法分析、语法分析调试(即将上线) 实时转译(即将上线)
PS C:\hulo> hulo-repl Hulo-REPL dev ➜ Type help for commands, exit to quit>>> e else Else statement enum Enum declaration extend Extend declaration exit Exit the REPL
🔧 技术改进
重构了 VBScript 转译器
- 代码结构更清晰,更易维护修复了
echo "Hello World"
字符串转译问题本次更新是一次破坏性更新,v0.1.0 版本所实现的功能可能部分无法在 v0.2.0 运行。尤其是涉及到 import 的地方,模块的设计会在接下来更近。
配置系统升级
hulo
命令现在支持从工作目录的 huloc.yaml
读取配置更灵活的项目配置管理🚧 下一步计划
- Batch 转译支持 - 让 Hulo 在 Windows 上更强大包发布系统 - 让社区能分享和复用代码Import 系统 - 支持第三方库导入命令体操 - 更智能的代码生成
💭 写在最后
项目地址: https://github.com/hulo-lang/hulo
如果你觉得这个项目有意思,欢迎在 GitHub 提 issue 或参与讨论!给个 Star 支持一下,让更多人看到这个项目。
你觉得这种"一次编写,多平台运行"的脚本开发方式怎么样?有什么建议或想法吗?