HaxeDoc2

(やまだぃちぅ) #1

  • The operators==,!=,>,>=,<,<=can be used to compare values.

  • Parentheses()can be used to group expressions as usual.


An exhaustive list of all built-in defines can be obtained by invoking the Haxe Compiler with
the--help-definesargument. The Haxe Compiler allows multiple-Dflags per compilation.

6.2 Externs


Externs can be used to describe target-specific interaction in a type-safe manner. They are defined
like normal classes, except that


  • theclasskeyword is preceded by theexternkeyword,

  • methods (4.3) have no expressions and

  • all argument and return types are explicit.


A common example from the Haxe Standard Library ( 10 ) is theMathclass, as an excerpt
shows:

1 extern class Math
2 {
3 static var PI(default,null):Float;
4 static function floor(v:Float):Int;
5 }


We see that externs can define both methods and variables (actually,PIis declared as a read-
only property (4.2)). Once this information is available to the compiler, it allows field access
accordingly and also knows the types:

1 class Main {
2 static public function main() {
3 var pi = Math.floor(Math.PI);
4 $type(pi); // Int
5 }
6 }


This works because the return type of methodflooris declared to beInt.
The Haxe Standard Library comes with many externs for the Flash and Javascript target.
They allow accessing the native APIs in a type-safe manner and are instrumental for designing
higher-level APIs. There are also externs for many popular native libraries on haxelib ( 11 ).
The Flash, Java and C# targets allow direct inclusion of native libraries from command line
( 7 ). Target-specific details are explained in the respective sections ofTarget Details(Chapter 12).
Some targets such as Python or JavaScript may require generating additional ”import” code
that loads anexternclass from a native module. Haxe provides ways to declare such depen-
dencies also described in respective sectionsTarget Details(Chapter 12).

6.3 Static Extension

Free download pdf