Tips and Tricks

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

This is a collection of small things that you can tweak in the language or compiler flags in order to get specific behavior.

Compiler Flags

You can define a flag with -D flagname commandline parameter. Some flags produce an additional effect :

  • check-xml-proxy : tells at the end of compilation which fields of the haxe.xml.Proxy are not used
  • dump : will create a /dump directory containing the dumped Haxe typed AST (for compiler debugging purposes or curious hackers)
  • macrotimes : print per-macro execution time results (to use together with --times)
  • no-compilation : generates Haxe/CPP code but does not compile it
  • neko-source : generates .neko source but does not compile it to .n
  • no-swf-compress : disable SWF output compression
  • haxe-boot : force the SWF boot class to be named haxe instead of boot_XXXX (automatic for SWC output)
  • fdb : include the Debugger tag in SWF output and extra debug infos (enable interactive debugging of Flash content)
  • network-sandbox : use the network sandbox flag for SWF output
  • swf-protected : by default the compiler turns all private fields as public in SWF output. This flag will keep them instead protected (AS3 protected == Haxe private)
  • noEmbedJS : disable automatic-embedding of JS files in standard library (so far used by both js.SWFObject and js.JQuery)

Compiler Metadata

If a metadata identifier starts with :, then the corresponding metadata will not get generated at runtime. Instead, it might be use by the Haxe compiler internals to perform specific tasks. Here's a list of used metadata compiler identifiers :

  • @:require(xxx) : will only allow to access the given field if the xxx compiler condition variable is set (for instance with -D xxx). Can also be set on a whole class, in that case the class can still be referenced but all its statics and its constructor accesses are forbidden if the xxx var is not set.
  • @:final : the given class cannot be subclassed anymore
  • @:hack : allow to subclass a class that was marked as final (use at your own risks)
  • @:native("my.real.Path") : the given class (and all its accesses) will be compiled as if its real class path was the one given in parameter. This make it more easy to bind "extern" classes that might have a different name.
  • @:core_api : identify this class as a "core api class". Its API will get checked against the abstract one declared in the Haxe standard library.
  • @:fakeEnum(Type) : tells Haxe compiler that this enum is just a collection of properties of given Type. In that case the compiler will not use enum switch for these, but instead classic switch. The Type can be used by the code generator backend to know actual field type (in general either String or Int)
  • @:macro and @:build , see Macros
  • @:keep: the given class or field will be preserved in the generated output even if never directly referenced (use it in conjunction with --dead-code-elimination)
  • @:overload : see below
  • @:extern static inline function foo() { ... } : this function will always be inlined but will not be generated as part of the resulting code new in 2.09

Flash Specific

In order to improve support for interacting with AS3 and Flash IDE, the following compiler metadata are available for Flash9+ platform only :

  • @:bind : when a class declared in Haxe without extern is already present in a SWF library, an error will be displayed. You can use @:bind before your class declaration to have it override the original SWF class declaration.
  • @:bitmap("myfile.png") class MyFile extends flash.display.BitmapData {} : include a given bitmap file into the target SWF and associate it to MyFile class. The file is looked-up using the classpath.
  • @:ns("namespace") : the specified field or method will be given this namespace
  • @:protected : the specified field or method is marked as protected (used when overriding protected methods for instance)
  • @:getter(x) function returnGetX() return 5 : will generate a native getter on the x property. Please note that the method returnGetX no longer exists, so do not call it directly.
  • @:setter(x) function setX( v : Float ) : Void { ... } : same as @:getter, but for setting the property.
  • @:meta(Event(name="test",type="Foo")) : generates the corresponding Flash metadata
  • @:debug function foo() { .... } : force debug information to be generated for this method (even when compiled without -debug) new in 2.09
  • @:nodebug function foo() { .... } : disable debug information for this method (even when compiled with -debug) new in 2.09

Overload

The @:overload metadata can be used when interfacing an external class method which arguments being of different types. You can declare the method in the following way :

@:overload(function(i:String):Bool{}) function foo( i : Int ) : Void;

You can have several overload declarations, the return type of the first one that is matched will be used.

Overload metadata is only useful for extern classes, it is most likely not usable for user-written Haxe classes.
Sohbetchatodalari.net google arama motorunda chat odaları ve sohbet odaları kelimelerinde hizmet veren bir chat odasıdır. Web sitemize bağlanarak keyifli bir sohbet ortamına sizde katılabilirsiniz.

version #11828, modified 2011-11-30 11:29:36 by Anonymous