Flow

The Flow language is a 3D visual dataflow language, which is based loosely on the Prograph programming language (https://en.wikipedia.org/wiki/Prograph). The official IDE for the Flow language is Newbound (https://github.com/mraiser/newbound).

Introductory Video:

Watch the video https://youtu.be/5vZKR4FGJyU

Installation

This repo can be used as a binary or a library. I assume if you are using this to develop something and want debug information, you already know how to convert the below instructions from "release" to "debug". To compile and use as a binary (on Linux):

cargo build --release
sudo cp target/release/flow /usr/bin/flow
sudo cp target/release/flowb /usr/bin/flowb

To use as a Rust library, add the following to your Cargo.toml file:

[dependencies]
flowlang = "0.1.5"
# NOTE: Change version to latest version: https://crates.io/crates/flowlang

To use as a native library in Java (on Linux), add libflowlang.so to your Java library path. Then add a native class in Java, like this one: https://github.com/mraiser/newbound/blob/master/runtime/botmanager/src/com/newbound/code/LibFlow.java

cargo build --release
sudo cp target/release/libflowlang.so /usr/lib/jni/libflowlang.so

Executing Flow Code

This repo includes a "data" folder which contains the "testflow" library. You can add your own libraries to the "data" folder, and they will become executable as well. Libraries are created using the Newbound Metabot (https://github.com/mraiser/newbound).

From the command line:

Execute the following from the directory that contains the "data" directory containing your Flow code.

flow testflow testflow test_add <<< "{\"a\": 300,\"b\":120}"

From Rust code:

DataStore::init("data");
Generated::init(); // Load any flow commands written in rust
env::set_var("RUST_BACKTRACE", "1");
{
    let args = DataObject::from_json(serde_json::from_str(r#"
    {
      "a": 299,
      "b": 121
    }
    "#).unwrap());
    let cmd = Command::lookup("testflow", "testflow", "test_add");
    let res = cmd.execute(args).unwrap();
    println!("Hello, my dudes! {}", res.to_json());
}
DataStore::gc();

From a web browser:

# Start the HTTP service from the directory where you installed Flow
flow flowlang http listen <<< "{\"socket_address\": \"127.0.0.1:7878\", \"library\":\"flowlang\", \"control\":\"http\", \"command\":\"parse_request\"}"

Test your HTTP service in a web browser:

http://127.0.0.1:7878/testflow/testflow/test_add?a=42&b=378

Support for commands in multiple languages

Flow commands can be written in Java, Python, Rust, Javascript, or Flow. However Python and Javascript are not currently supported in this implementation of the Flow language interpreter. When developing Flow code using Newbound, the IDE automatically builds, compiles, and runs any files needed. Newbound has its own instructions for enabling support for multiple languages (https://github.com/mraiser/newbound). The following only applies to running Flow code outside of the Newbound IDE.

Enabling Rust commands:

In order to run Libraries that contain commands written in Rust, you will need to copy them into your data folder and then compile them.

# From the directory containing the "data" directory with your flow code that has rust commands
flowb all
cargo build --release
# Example from testflow library:
flow testflow testflow test_rust <<< "{\"a\":1, \"b\":2}"

Enabling Java commands

In order to run Libraries that contain commands written in Java, you will need the data, runtime, and src folders from Newbound (https://github.com/mraiser/newbound).

mkdir bin
cd src
javac -d ../bin Startup.java
cd ../
# Example from testflow library:
flow testflow testflow test_java <<< "{\"abc\":\"xxx\"}"

Background:

Flow was originally written in Java as part of Newbound, an integrated development and runtime environment for peer-to-peer HTML5 web apps. Newbound supports Java, Python, Rust, and Flow for server-side commands, and Javascript and Flow on the front-end. This repository contains a port of the Flow language interpreter from Newbound's Java implementation. Newbound also uses this repo to compile and execute Rust code.