An embeddable dynamic programming language for Rust.
If you want to help out, there should be a number of optimization tasks available in Future Optimizations. Or have a look at Open Issues.
Create an issue about the optimization you want to work on and communicate that you are working on it.
- Clean Rust integration 💻.
- Memory safe through reference counting 📖.
- Template strings 📖.
- Try operators 📖.
- Pattern matching 📖.
- Structs and enums 📖 with associated data and functions.
- Dynamic vectors 📖, objects 📖, and tuples 📖 with built-in serde support 💻.
- First-class async support 📖.
- Generators 📖.
- Dynamic instance functions 📖.
- Stack isolation 📖 between function calls.
- Stack-based C FFI, like Lua's (TBD).
You can run Rune programs with the bundled CLI:
cargo run -- scripts/hello_world.rn
If you want to see detailed diagnostics of your program while it's running, you can use:
cargo run -- scripts/hello_world.rn --dump-unit --trace --dump-vm
See --help
for more information.
You can find more examples in the
examples
folder.
The following is a complete example, including rich diagnostics using
termcolor
. It can be made much simpler if this is not needed.
use rune::termcolor::{ColorChoice, StandardStream};
use rune::EmitDiagnostics as _;
use runestick::{Vm, FromValue as _, Item, Source};
use std::error::Error;
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let source = Source::new(
"script",
r#"
fn calculate(a, b) {
println("Hello World");
a + b
}
"#,
);
let context = Arc::new(rune::default_context()?);
let options = rune::Options::default();
let mut warnings = rune::Warnings::new();
let unit = match rune::load_source(&*context, &options, source, &mut warnings) {
Ok(unit) => unit,
Err(error) => {
let mut writer = StandardStream::stderr(ColorChoice::Always);
error.emit_diagnostics(&mut writer)?;
return Ok(());
}
};
if !warnings.is_empty() {
let mut writer = StandardStream::stderr(ColorChoice::Always);
rune::emit_warning_diagnostics(&mut writer, &warnings, &unit)?;
}
let vm = Vm::new(context.clone(), Arc::new(unit));
let mut execution = vm.call(&["calculate"], (10i64, 20i64))?;
let value = execution.async_complete().await?;
let value = i64::from_value(value)?;
println!("{}", value);
Ok(())
}