Next: , Previous: , Up: Top  


12 Foreign Functions

k9 is able to interface with other programing laguages via it’s foreign function interface (ffi).

python:from k import k;k('+',2,3);nodejs:k=require('k').k;k('+',2,3)
*ffi:"./a.so"5:`a!"fi" //double a(int x){return 2.3+x;}

Enterprise only

12.1 ffi ⇒ 5:

Load shared library.

Contents of file ’a.c’

int add1(int x){return 1+x;}
int add2(int x){return 2+x;}
int indx(int x[],int y){return x[y];}

Compile into a shared library (done on macos here)

% clang -dynamiclib -o a.so a.c

Load the shared library into the session.

 f:"./dev/a.so"5:{add1:"i";add2:"i";indx:"Ii"}
 f[`add1] 12
13
 f[`indx][12 13 14;2]
14