molt

Crates.iomolt
lib.rsmolt
version0.3.1
sourcesrc
created_at2019-09-18 02:10:50.415338
updated_at2020-05-11 01:48:33.295694
descriptionEmbeddable TCL interpreter for Rust applications
homepagehttps://wduquette.github.io/
repositoryhttps://github.com/wduquette/molt
max_upload_size
id165583
size459,337
Will Duquette (wduquette)

documentation

README

molt -- An Embeddable Tcl Interpreter for Rust

New in Molt 0.3.1

See the Annotated Change Log in the Molt Book for the complete list of new features by version.

Description

Molt is an embeddable TCL interpreter for Rust. Applications can define new TCL commands in Rust and execute TCL scripts and strings. For example,

use molt::Interp;
let mut interp = Interp::new();

let four = interp.eval("expr {2 + 2}")?;
assert_eq!(four.as_int(), 4);

A new command is defined like so:

use molt::check_args;
use molt::MoltResult;
use molt::Value;
use molt::Interp;
use molt::molt_ok;

/// # square *x*
///
/// Computes the square of a value
pub fn cmd_square(_interp: &mut Interp, _: ContextID, argv: &[Value]) -> MoltResult {
    // Correct number of arguments?
    check_args(1, argv, 2, 2, "x")?;

    // Get x, if it's an integer
    let x = argv[1].as_int()?;

    // Return the result.
    molt_ok!(x * x)
}

and installed like so:

use molt::Interp;
let mut interp = Interp::new();
interp.add_command("square", cmd_square);

let num = interp.eval("square 5")?;
assert_eq!(num.as_int(), 25);

Values are represented by the Value type, which can be converted to and from any type consistent with the value's string representation: integers, floats, lists, and any type that defines the MoltAny trait.

Molt is still a work in progress. The basic TCL language is in place, but many TCL commands remain to be implemented. See the Molt Book for details.

The molt-sample repo contains a sample Molt extension, including a shell application and a library create, both of which define new Molt commands.

See my blog for news, The Molt Book for details, and the GitHub Repo for issue tracking, etc.

Commit count: 537

cargo fmt