Crate rune[−][src]
Expand description
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
- Clean Rust integration 💻.
- Memory safe through reference counting 📖.
- Template literals 📖.
- 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).
Rune scripts
You can run Rune programs with the bundled CLI:
cargo run --bin rune -- run 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 -- run 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.
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 context = runestick::Context::with_default_modules()?; 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 diagnostics = rune::Diagnostics::new(); let result = rune::load_sources(&context, &options, &mut sources, &mut diagnostics); if !diagnostics.is_empty() { let mut writer = StandardStream::stderr(ColorChoice::Always); diagnostics.emit_diagnostics(&mut writer, &sources)?; } let unit = result?; let vm = Vm::new(Arc::new(context.runtime()), 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(()) }
Re-exports
pub use self::emit_diagnostics::termcolor;
Modules
Macros
Helper macro to reference a specific token kind, or short sequence of kinds.
Helper macro to reference a specific token.
Macro helper function for quoting the token stream as macro output.
Structs
An error raised during compiling.
Structure to collect compilation diagnostics.
An error raised when using one of the load_*
functions.
A filesystem-based source loader.
An opaque identifier that is associated with AST items.
A single stap as an import entry.
An error raised during compiling.
Lexer for the rune language.
Error raised when we failed to load sources.
Context for a running macro.
A compile visitor that does nothing.
Compiler options.
An error raised during parsing.
Parser for the rune language.
Construct used to peek a parser.
An error raised during querying.
An error during resolving.
An error cause by issues with scoping.
A collection of source files, and a queue of things to compile.
Storage for synthetic language items.
A token stream.
A token stream iterator.
Instructions from a single source file.
Compilation warning.
Enums
Compiler error.
Error when parsing configuration.
A single diagnostic.
Errors that can be raised when formatting diagnostics.
Error when encoding AST.
A constant value.
An error raised during linking.
Error when parsing.
Error raised during queries.
The kind of a resolve error.
Indication whether a value is being evaluated because it’s being used or not.
Compilation warning kind.
Traits
A visitor that will be called for every language item compiled.
Trait to dump the instructions of a unit to the given writer.
Helper trait for emitting diagnostics.
Helper trait to emit source code locations.
Types for which we can optionally get a span.
The parse trait, implemented by items that can be parsed.
Implemented by tokens that can be peeked for.
A type that can be resolved to an internal value based on a source.
Trait for resolving a token into an owned value.
A source loader.
Types for which we can get a span.
Trait for things that can be turned into tokens.
Functions
Compile the given source with default options.
Load and compile the given sources.
Load the specified sources with a visitor.
Parse the given input as the given type that implements Parse.
Install the given context and call the provided function with the installed context.
Type Definitions
A compile result.