metacall 0.2.0

Call NodeJS, TypeScript, Python, C#, Ruby... functions from Rust (a Rust Port for MetaCall).
Documentation

Abstract

METACALL is a library that allows calling functions, methods or procedures between programming languages. With METACALL you can transparently execute code from / to any programming language, for example, call TypeScript code from Rust.

Install

MetaCall is a C plugin based library. This crate wraps the C library into Rust, so in order to make it work, you should install MetaCall binaries first (click here for additional info about the install script):

bash <(curl -sL https://raw.githubusercontent.com/metacall/install/master/install.sh)

Example

sum.ts

export function sum(a: number, b: number): number {
	return a + b;
}

main.rs

fn main() {
    let _d = defer(metacall::destroy);

    match metacall::initialize() {
        Err(e) => {
            println!("{}", e);
            panic!();
        }
        _ => println!("MetaCall initialized"),
    }

    let scripts = ["sum.ts".to_string()];

    if let Err(e) = crate::load_from_file("ts", &scripts) {
        println!("{}", e);
        panic!();
    }

    match metacall::metacall(
        "sum",
        &[metacall::Any::Double(1.0), metacall::Any::Double(2.0)],
    ) {
        Err(e) => {
            println!("{}", e);
            panic!();
        }
        Ok(ret) => {
            println!("{:?}", ret);
        }
    }
}