Contains three useful files:
FFI-Bindings.rktlets you bind FFI functions using Racket'sffi/unsafemodule, but extends the Racket notion ofcpointertypes to includec++pointertypes, which support subtyping and upcasts.Cxx-Types.rktlets you automatically definec++pointertypes for the entire type hierarchy of some API, by parsing JSON descriptions of inheritance relations emitted by this library, to discover symbol names of functions implementing the necessary upcasts (a C++ file containing the necessary functions can be emitted using the same Python utilities).private/interactive-helpers.rktallows you to easily preload a set of libraries into the Racket address space, so thatFFI-Bindings.rktdoesn't need to know about specific path to libraries.
An example usage, based on a hypothetical FFI for Cxx-TEDSL might look like this:
(define-c++ makeFloat
(_fun _float -> _TEDSL::Float))
(define-c++ makePlus
(_fun _TEDSL::Expr<TEDSL::Number>++
_TEDSL::Expr<TEDSL::Number>++ -> _TEDSL::Plus))
(makePlus (makeFloat 1.0) (makeFloat 3.0))(In this example Float is a subtype of Expr<Float>, Number, and Expr<Number>, so the FFI wrapper for makePlus, would automatically be able to find the necessary upcasts).
It should be possible to reliably track ownership of these pointers, using the allocator, deallocator and retainer wrappers in ffi/unsafe/alloc, but the documentation for these functions is dense.