Skip to content

Latest commit

 

History

History
115 lines (75 loc) · 2.94 KB

README.md

File metadata and controls

115 lines (75 loc) · 2.94 KB

SKILL FFI

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.

Dependencies

Build Utils:

  • GCC version 4.8.5
  • GNU Make version 3.82

Libraries:

  • ffi.h
  • dlfcn.h

Getting Started

Building

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 skillFFI.

Example Usage

Start by loading ffi.il in the CIW:

(load "ffi.il")

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 libm. Since there is no access to header files in SKILL the function prototype must be defined manually.

(setq sqrtf (ffiDefun libm "sqrtf" "float" (list "float")))

If successful ffiDefun returns a handle to the prototyped function, which can be called with ffiCallFun.

(setq res (ffiCallfun fnSqrt (list 144.0)))

Function Reference

ffiOpenLib

(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

(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

(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 ffiDefun.
  • fnArgs is a list of arguments corresponding to the correct types given in the definition.

ffiCloseLib

ffiCloseLib libHandle)

Closes the library.