Crates.io | molt |
lib.rs | molt |
version | 0.3.1 |
source | src |
created_at | 2019-09-18 02:10:50.415338 |
updated_at | 2020-05-11 01:48:33.295694 |
description | Embeddable TCL interpreter for Rust applications |
homepage | https://wduquette.github.io/ |
repository | https://github.com/wduquette/molt |
max_upload_size | |
id | 165583 |
size | 459,337 |
See the Annotated Change Log in the Molt Book for the complete list of new features by version.
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.