10 releases

0.4.2 Sep 25, 2024
0.4.1 Jul 29, 2024
0.4.0 Jun 14, 2023
0.3.0 Apr 7, 2022
0.1.1 Oct 23, 2020

#39 in FFI

Download history 23/week @ 2024-07-01 174/week @ 2024-07-29 9/week @ 2024-08-19 34/week @ 2024-09-16 178/week @ 2024-09-23 19/week @ 2024-09-30 8/week @ 2024-10-07

239 downloads per month

Apache-2.0

330KB
8K SLoC

M E T A C A L L

M E T A C A L L

A library for providing inter-language foreign function interface calls

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 installing it on other platforms):

curl -sL https://raw.githubusercontent.com/metacall/install/master/install.sh | sh

Example

sum.ts

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

main.rs

use metacall::{switch, metacall, loaders};

fn main() {
    // Initialize Metacall at the top
    let _metacall = switch::initialize().unwrap();
     
    // Load the file
    loaders::from_single_file("ts", "sum.ts").unwrap();

    // Call the sum function
    let sum = metacall::<f64>("sum", [1.0, 2.0]).unwrap();

    assert_eq!(sum, 3.0);
}

Dependencies

~78KB