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 Python code from NodeJS.
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)
Then install MetaCall Dub package:
dub add metacall
sum.py
def sum(a, b):
return a + b
main.d
import std.stdio;
import std.variant;
import metacall; // Import MetaCall
int main()
{
dmetacall_initialize();
string[] scripts = [
"script.py"
];
dmetacall_load_from_file("py",scripts);
Variant ret = dmetacall!(int,int)("add",1,2);
writefln("add(1,2) = %d",ret.get!(long)); // 3
dmetacall_destroy();
return 0;
}
In order to test you'll have to run dub add-local ..
in the test folder.