When this is the
situation, it is possible to use the compiled library but it will be necessary to use reflection and untyped
blocks to reach the library contents. To simplify the access to the imported types, it is also possible to
define some kind of header files (in the C/C++ sense) that map the library functionalities to classes
usable in haXe.
Extern Classes
When a library that contains definitions for classes is imported and there is the need of a strictly typed
approach, one or more extern classes must be defined. The haXe compiler, to check that the code is
syntactically correct, will use those classes. The extern classes are different from normal classes because
their functions do not implement a body; this is not required because the real implementation is
encountered in the external library and the extern class works like a pointer to the external resource.
External classes can declare external functions for both static and instance fields, as shown in the
following code;
extern class ExternalClass
{
public function externalInstanceMethod() : Void;
public static function externalStaticMethod() : Void;
}
In addition, typedef can be used to map external structures.
Pages:
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306