CFFI Package

The cffi package is an extension that implements a Foreign Function Interface for Tcl. It is based on the dyncall library available from https://dyncall.org .

The repository for the package is at https://github.com/apnadkarni/tcl-cffi . Current release is 1.0a5.

Documentation pages are at https://cffi.magicsplat.com .

Source distributions and binary packages for some platforms are at https://sourceforge.net/projects/magicsplat/files/cffi .

Distinguishing features of the package are

  • Automatic conversion of numerics, strings, structures and arrays to and from the corresponding Tcl script values
  • Safety mechanisms to protect against pointer errors like double frees, mismatched types
  • Support for automatic encoding of string values passed and returned from C functions
  • Exception generation based on error annotations
  • Proc-like argument processing with defaults, error messages etc.
  • Utilities for managing memory and conversion to native formats
  • Extensible type aliases for common system definitions
  • Introspection

Limitations (as of 1.0 Alpha 5) include

  • No support for arrays of non-scalars
  • No support of functions taking variable number of arguments
  • No support for callbacks from C code
  • No support for passing structs by value