rune

Rune Logo


Visit the site 🌐 - Read the book 📖


Build Status Site Status crates.io docs.rs Chat on Discord


An embeddable dynamic programming language for Rust.

Contributing

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.


Highlights of Rune


Rune scripts

You can run Rune programs with the bundled CLI:

cargo run --bin rune -- scripts/hello_world.rn

If you want to see detailed diagnostics of your program while it's running, you can use:

cargo run --bin rune -- scripts/hello_world.rn --dump-unit --trace --dump-vm

See --help for more information.

Running scripts from Rust

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.

```rust 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> { let context = Arc::new(runemodules::defaultcontext()?); let options = rune::Options::default();

let mut sources = rune::Sources::new();
sources.insert(Source::new(
    "script",
    r#"
    pub fn calculate(a, b) {
        println("Hello World");
        a + b
    }
    "#,
));

let mut errors = rune::Errors::new();
let mut warnings = rune::Warnings::new();

let unit = match rune::load_sources(&*context, &options, &mut sources, &mut errors, &mut warnings) {
    Ok(unit) => unit,
    Err(rune::LoadSourcesError) => {
        let mut writer = StandardStream::stderr(ColorChoice::Always);
        errors.emit_diagnostics(&mut writer, &sources)?;
        return Ok(());
    }
};

if !warnings.is_empty() {
    let mut writer = StandardStream::stderr(ColorChoice::Always);
    warnings.emit_diagnostics(&mut writer, &sources)?;
}

let vm = Vm::new(context.clone(), Arc::new(unit));

let mut execution = vm.execute(&["calculate"], (10i64, 20i64))?;
let value = execution.async_complete().await?;

let value = i64::from_value(value)?;

println!("{}", value);
Ok(())

} ```