Rune Programming Language

repository·main·Indexed 25 days ago

https://github.com/rune-rs/rune

An embeddable dynamic programming language designed for Rust, featuring a high-performance stack-based virtual machine, async support, and multithreading. The ecosystem includes the main rune crate for embedding, rune-cli for script execution, rune-languageserver for LSP support, and specialized crates like rune-wasm for WebAssembly and rune-modules for extended functionality.

Tokens
36.6K
Snippets
97
Records
256
Agent score
81%

What's inside Rune

  1. Overview of Rune features

    main

    Rune is an embeddable dynamic programming language for Rust. Key features include:

    • Execution Model: Runs a compact language representation on an efficient stack-based virtual machine with stack isolation between function calls.
    • Concurrency & Async: Supports multithreaded execution and first-class async support with Generators.
    • Memory Management: Memory safe through reference counting.
    • Language Features: Pattern matching, try operators, structs/enums with associated data, template literals, and awesome macros.
    • Data Types: Dynamic containers like vectors, objects, and tuples, all with out-of-the-box serde support.
    • Integration: Clean Rust integration and support for hot reloading.
  2. Use rune-wasm in WebAssembly environments

    main
    The rune-wasm crate provides a WebAssembly (WASM) module for the Rune Language. This allows you to run Rune scripts within web browsers or other WASM-compatible runtimes. It is a specialized build of the Rune engine designed for portability in WASM environments.
  3. Use rune-tracing-macros for tracing the Rune Language

    main
    The rune-tracing-macros crate provides macros designed to facilitate tracing within the Rune Language, an embeddable dynamic programming language for Rust. These macros allow developers to instrument their code to gain insights into the execution and behavior of Rune scripts.
  4. Use the rune-languageserver for Rune development

    main
    rune-languageserver is a Language Server Protocol (LSP) implementation for the Rune language. It provides IDE and editor support for Rune scripts, which are embeddable dynamic programming scripts used within Rust applications. You can use this language server to enable features like autocompletion, diagnostics, and navigation in editors that support LSP (such as VS Code, Neovim, or Sublime Text).
  5. Use rune-modules in Rune scripts

    main
    The rune-modules crate provides native modules for the Rune dynamic programming language. These modules extend Rune's capabilities by providing access to standard functionality like file system access, HTTP requests, JSON parsing, and more. To use them, you must include the appropriate module in your Rune environment.
  6. How instance functions work in Rune

    main
    Instance functions are functions associated with a specific type of variable, called using the syntax value.foo(). Because Rune is a dynamic language, the virtual machine performs a runtime lookup to find the function associated with the specific instance. If the function is not found for the given type, the VM will throw a virtual machine error indicating a missing instance function for the specific type hash.
  7. Pattern match on external enums

    main

    Rune supports pattern matching on external enums out of the box. However, pattern matching will only recognize and allow access to fields that are explicitly annotated with #[rune(get)] in the Rust definition.

    This applies to:

    • Tuple variants: Only the annotated fields are visible in the pattern.
    • Struct variants: Only the annotated named fields are visible in the pattern.

    Example of pattern matching on a tuple variant where only the first field is visible:

    enum External {
        First(#[rune(get)] u32, u32),
        Second(#[rune(get)] u32),
    }
    pub fn main(external) {
        match external {
            External::First(a) => a,
            External::Second(b) => b,
        }
    }
  8. Send values into a generator using `yield`

    main
    The yield keyword in Rune is bidirectional. While it is used to produce a value to the caller, it can also receive a value sent from the calling procedure. This allows you to inject data back into the generator's execution context during a resume call.
  9. How statics hold values

    main
    In Rune, statics hold reference-counted values. When you read a static, you receive a handle to the same instance held by the static. Consequently, mutating the value through that handle mutates the value stored in the static directly, without needing an explicit assignment to the static itself.
  10. Convert functions to function pointers

    main
    In Rune, any function can be converted into a function pointer by referencing its name without calling it (i.e., without using parentheses ()). This allows you to pass functions as arguments to other functions to define operations dynamically.