44个版本
0.13.4 | 2024年7月23日 |
---|---|
0.13.2 | 2024年3月7日 |
0.13.1 | 2023年10月10日 |
0.12.4 | 2023年6月9日 |
0.0.0 | 2018年7月12日 |
#30 in 编程语言
3,481 每月下载
用于 15 个crate (14 直接)
4.5MB
99K SLoC
包含 (WOFF字体, 1.5MB) NanumBarunGothic-Regular.woff2, (WOFF字体, 135KB) FiraSans-Medium.woff2, (WOFF字体, 130KB) FiraSans-Regular.woff2, (WOFF字体, 75KB) SourceCodePro-Regular.woff2, (WOFF字体, 75KB) SourceCodePro-Semibold.woff2, (WOFF字体, 82KB) SourceSerif4-Bold.woff2 和更多.
rune
Rune语言,Rust的嵌入式动态编程语言。
贡献
如果您想帮忙,请查看 开放问题。
Rune亮点
- 在高效的基础虚拟机之上运行语言的紧凑表示。
- 简洁的 Rust集成 💻。
- 通过 引用计数 📖 确保内存安全。
- 出色的宏 📖.
- 模板字符串 📖.
- 尝试运算符 📖.
- 模式匹配 📖.
- 结构体和枚举 📖 带有关联数据和函数。
- 动态 向量 📖、对象 📖 和 元组 📖,带出盒式 serde支持 💻。
- 一等 异步支持 📖。
- 生成器 📖.
- 动态 实例函数 📖。
- 函数调用之间的堆栈隔离 📖。
Rune脚本
您可以使用捆绑的CLI运行Rune程序
cargo run --bin rune -- run scripts/hello_world.rn
如果您想在程序运行时查看详细的诊断信息,可以使用
cargo run --bin rune -- run scripts/hello_world.rn --dump-unit --trace --dump-vm
请参阅 --help
获取更多信息。
从 Rust 运行脚本
更多示例可以在 示例文件夹
examples
中找到。
以下是一个完整示例,包括使用 termcolor
的丰富诊断。如果不需要,可以使其变得更加简单。
use rune::{Context, Diagnostics, Source, Sources, Vm};
use rune::termcolor::{ColorChoice, StandardStream};
use std::sync::Arc;
let context = Context::with_default_modules()?;
let runtime = Arc::new(context.runtime()?);
let mut sources = Sources::new();
sources.insert(Source::memory("pub fn add(a, b) { a + b }")?);
let mut diagnostics = Diagnostics::new();
let result = rune::prepare(&mut sources)
.with_context(&context)
.with_diagnostics(&mut diagnostics)
.build();
if !diagnostics.is_empty() {
let mut writer = StandardStream::stderr(ColorChoice::Always);
diagnostics.emit(&mut writer, &sources)?;
}
let unit = result?;
let mut vm = Vm::new(runtime, Arc::new(unit));
let output = vm.call(["add"], (10i64, 20i64))?;
let output: i64 = rune::from_value(output)?;
println!("{}", output);
依赖项
~4–19MB
~252K SLoC