C Foreign Function Interface

You are viewing an old version of this entry, click here to see latest version.

Introduction

This tutorial demonstrates how to call external C/C++ code from a haxe application. In many ways, the system is similar to the neko C Foreign Function Interface, with the main difference being that the "value" types are treaded as "opaque".

The "value" Type


All arguments and return data used for communicating between the Haxe compiled code and the native library code are declared as type "value". On the Neko target, this is a very particular data structure, and the type of element that is referred to by it can be determined by looking directly at the bits in the value variable. This means that in order for the C++ traget to be able to use the Neko ndll files directly, it would have to convert to and from these Neko values for each CFFI call. For efficiency reasons, the C++ target does not do this. Instead, as far as the external library is concerned, the value type is a generic pointer to an unknown type.
version #8180, modified 2010-03-05 06:22:14 by gamehaxe