[][src]Function rune::load_path

pub fn load_path(
    context: &Context,
    options: &Options,
    warnings: &mut Warnings,
    path: &Path
) -> Result<Unit, LoadError>

Load the given path.

The name of the loaded source will be the path as a string.

If you want to load a script from memory use load_source.

Examples

Note: these must be built with the diagnostics feature enabled to give access to rune::termcolor.

use rune::termcolor::{ColorChoice, StandardStream};
use rune::EmitDiagnostics as _;

use std::path::Path;
use std::sync::Arc;
use std::error::Error;

let path = Path::new("script.rn");

let context = Arc::new(rune::default_context()?);
let mut options = rune::Options::default();
let mut warnings = rune::Warnings::new();

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

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

if !warnings.is_empty() {
    let mut writer = StandardStream::stderr(ColorChoice::Always);
    rune::emit_warning_diagnostics(&mut writer, &warnings, &*unit)?;
}