Coder Social home page Coder Social logo

caat_rust's Introduction

CAAT for Rust

Commands as Arrow Types for Rust

CAAT provides a way for programs to call each other regardless of the language used as if they were functions. This is the library for the Rust language, it provides the required functions, structs, and macros for making programs that can call foreign code.

How it works

When you call a foreign command, an environment variable called CAAT_ARGS is set with a JSON string that represents the arguments passed into the function. They are also passed in via the command line arguments but this is for legacy reasons. The JSON string gets parsed into a format that the language can understand. At the same time, the caller opens up a socket at /tmp/caat_pid.sock where pid is the pid of the caller process. This is set as the CAAT_SOCKET variable which is also passed into the callee. When the callee is done with what it is doing, it should call the function or macro that will write the return value back to the caller. This will also end the program.

Example

Program 1

use caat;

fn main() {
    let ff = caat::ForeignFunction::new("other");

    let return_value = ff.call(&[caat::Value(String::from("Hello, World!"))]);

    println!("{}", return_value);
}

Program 2

use caat;

fn main() {
    let args = caat.args();
    println!("{}", args.next().unwrap());

    return_caat!("Successful print!");
}

Output

./program_1
Hello, World!
Successful print!

caat_rust's People

Contributors

ki11errabbit avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.