With the Foreign Function Interface (FFI) for SKILL C-Type Libraries can be loaded and used within the SKILL environment.
State of Development
This is not a finished product and still very early in development.
For now the only data type supported is float other data types as well as defining custom structs is still in development.
- GCC version 4.8.5
- GNU Make version 3.82
Make sure the latest version of GNU Make and GCC are installed and build the project with
$ make ffi
This should result in an executable named
Start by loading ffi.il in the CIW:
This should print a confirmation
FFI up and running
To load a shared library either the complete and absolute path must be provided or it has to be located in the LD_LIBRARY_PATH environment variable.
Loading the C math library is accomplished like so:
(setq libm (ffiOpenLib "libm.so")
ffiOpenLib loads the library and returns a memory address as handle, which
in this example will be stored in the variable
Since there is no access to header files in SKILL the function prototype must be
(setq sqrtf (ffiDefun libm "sqrtf" "float" (list "float")))
ffiDefun returns a handle to the prototyped function, which
can be called with
(setq res (ffiCallfun fnSqrt (list 144.0)))
(ffiOpenLib libName) => libHandle
Opens a shared library and returns a handle to it. libName can either be the entire absolute path to a library or just its name if the path is in the LD_LIBRARY_PATH environment variable.
- libName is a string with the entire absolute path to the library.
(ffiDefun libHandle fnName rType aTypes) => fnHandle
Defines the prototype for a C function and returns a handle to it if succesful.
The libHandle is a handle returned by
ffiOpenLib. The name of the function
has to be known in advance and passed as fnName. The return type of the function
is the string rType. aTypes is a string list with the types of arguments.
- libHandle is a string containing a handle to an open shared library.
- The name of the function is a string in fnName.
- rType is the return type of the function as a string.
- aTypes is a string list containing the types of the function arguments.
(ffiCallfun fnHandle fnArgs) => result
Calls a previously defined function with the given arguemnts in fnArgs and returns whatever this function call retured.
- fnHandle is a string containing a function handle obtained by
- fnArgs is a list of arguments corresponding to the correct types given in the definition.
Closes the library.