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:"./"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.c

Load the shared library into the session.

 f[`add1] 12
 f[`indx][12 13 14;2]