Haxe Low Level Notes
Low level boring stuff. ;-)
Macros
- Initialization Macros: These are provided by command line using the
--macro compiler
parameter. They are executed after the compiler arguments were processed and the typer context has been created, but before any typing was done (see Initialization Macros). - Build Macros: These are defined for classes, enums and abstracts through the
@:build
or@:autoBuild
metadata. They are executed per type, after the type has been set up (including its relation to other types, such as inheritance for classes) but before its fields are typed (see Type Building). - Expression Macros: These are normal functions which are executed as soon as they are typed.
XML
1-20-2021
I have not heard any updates about XML literals in Haxe. I did spend an afternoon playing around with my prototype some more recently, though. I added support for event listeners containing Haxe code in the XML (like
<Button click="trace('hi')"/>
.
I tried adding a
<Script>
tag too, but I couldn’t find a way to directly copy the user’s code using a macro. Seems like they only support copying blocks of code and not full method signatures.
the main thing with the XML that I’m stuck on is trying to implement
<Script>
See Also
- https://haxe.org/manual/macro.html
- http://api.haxe.org/haxe/macro
- https://haxe.org/manual/macro-type-building.html|Macro - Type Building
- https://code.haxe.org/category/macros/include-file-next-to-module-file.html
- http://code.haxe.org/category/macros/
- https://code.haxe.org/category/macros/combine-objects.html - Combine Objects
- https://api.haxe.org/haxe/macro/Context.html#parse - Read arbitrary haxe code
- https://api.haxe.org/haxe/macro/Context.html#parse -
Macro.parse()
Git
- https://try.haxe.org/#501b1 -Use GIT API to read last update times
Haxe RTTI
Classes
Abstractdef
- The abstract type runtime information.CType
- The runtime member types.CTypeTools
- TheCTypeTools
class contains some extra functionalities for handlingCType
instances.ClassField
- The runtime class field information.Classdef
- The runtime class definition information.EnumField
- The runtime enum constructor information.Enumdef
- The enum runtime type information.FunctionArgument
- The function argument runtime type information.Meta
- An API to access classes and enums metadata at runtime.MetaData
- The list of runtime metadata.Path
- The (dot-)path of the runtime type.PathParams
- The type parameters in the runtime type information.Platforms
- A list of strings representing the targets where the type is available.Rights
- Represents the runtime rights of a type.Rtti
- Rtti is a helper class which supplements the@:rtti
metadata.TypeApi
- Contains type and equality checks functionalities for RTTI.TypeInfos
- The general runtime type information.TypeParams
- An array of strings representing the names of the type parameters the type has.TypeRoot
- Array ofTypeTree
.TypeTree
- The tree types of the runtime type.Typedef
- The typedef runtime information.XmlParser
-XmlParser
processes the runtime type information (RTTI) which is stored as a XML string in a static field __rtti.
TypeTree
- TPackage(name:
String
, full:String
, subs:Array<TypeTree>
) - TClassdecl(c:
Classdef
)- [Classdef]
- tdynamic:
Null<CType>
- [CType]
- CUnknown
- CEnum(name:
Path
, params:Array<CType>
) - CClass(name:
Path
, params:Array<CType>
) - CTypedef(name:
Path
, params:Array<CType>
) - CFunction(args:
Array<FunctionArgument>
, ret:CType
)- [FunctionArgument]
- optionalvalue:
Null<String>
- t:
CType
- opt:
Bool
- name:
String
- CAnonymous(fields:
Array<ClassField>
) - CDynamic(t:
CType
) - CAbstract(name:
Path
, params:Array<CType>
)
- superClass:
Null<PathParams>
- [PathParams]
- path:
Path
//aias of// (String
) - params:
Array<CType>
- statics:
Array<ClassField>
- platforms:
Platforms
//aias of// (Array<String>
) - path:
Path
- params:
TypeParams
//aias of// (Array<String>
) - module:
Path
- meta:MetaData //aias of// (
Array<{params:Array<String>, name:String}>
) - isPrivate:
Bool
- isInterface:
Bool
- isFinal:
Bool
- isExtern:
Bool
- interfaces:
Array<PathParams>
- file:
Null<String>
- fields:
Array<ClassField>
- [ClassField]
- type:
CType
- set:
Rights
- [Rights]
- RNormal
- RNo
- RCall(m:
String
) - RMethod
- RDynamic
- RInline
- platforms:
Platforms
- params:TypeParams
- overloads:
Null<Array<ClassField>>
- name:
String
- meta:
MetaData
- line:
Null<Int>
- isPublic:
Bool
- isOverride:
Bool
- isFinal:
Bool
- get:
Rights
- expr:
Null<String>
- doc:
Null<String>
- doc:
Null<String>
- TEnumdecl(e:
Enumdef
)- platforms:
Platforms
- path:
Path
- params:
TypeParams
- module:
Path
- meta:
MetaData
- isPrivate:
Bool
- isExtern:
Bool
- file:
Null<String>
- doc:
Null<String>
- constructors:
Array<EnumField>
- platforms:
- TTypedecl(t:
Typedef
)- types:
Map<String, CType>
- type:
CType
- platforms:
Platforms
- path:
Path
- params:
TypeParams
- module:
Path
- meta:
MetaData
- isPrivate:
Bool
- types:
- TAbstractdecl(a:
Abstractdef
)- to:
Array<{t:CType, field:Null<String>}>
- platforms:
Platforms
- path:
Path
- params:
TypeParams
- module:
Path
- meta:
MetaData
- isPrivate:
Bool
- impl:
Classdef
- from:
Array<{t:CType, field:Null<String>}>
- file:
Null<String>
- doc:
Null<String>
- athis:
CType
- to:
See Also
- https://api.haxe.org/haxe/rtti/index.html
- https://api.haxe.org/haxe/rtti/XmlParser.html
- https://haxe.org/manual/cr-rtti.html
Native Extensions
Ammer
class Adder extends Library<"adder"> { public static function add_numbers(a:Int, b:Int):Int; public static function load_file(filename:String, loaded:SizeOfReturn):Bytes; public static function concat_strings(a:String, b:String):String; public static function reverse_bytes(data:Bytes, dataLen:SizeOf<"data">):SameSizeAs<Bytes, "data">;}
$ haxelib dev ammer <path to clone>$ cd ammer/samples/poc/native# <compile the native library somehow, preferably place it in /usr/local/lib or equivalent>$ cd ..$ haxe build-hl.hxml$ hl bin/hl/sample.hl
ammer
assumes you have a dynamic library and its headers.
- https://github.com/Aurel300/ammer - Unified FFI for native extensions for Haxe.
- https://aurel300.github.io/ammer/ -
ammer
is a Haxe 4 library which brings native libraries (.dll
,.dylib
,.so
) to a variety of Haxe targets without requiring the user to manually write similar but slightly different extern definitions and target-specific stub/glue code. - https://github.com/Aurel300/ammer/tree/master/samples/poc/ - POC C library with Haxe impl.
- https://community.haxe.org/t/wrap-c-library-in-haxecpp/2486
- https://github.com/jeremyfa/bind - Bind Objective-C/Swift and Java/JNI code to Haxe without writing glue code manually.
See Also
Resources
- https://haxe.org/manual/cr-metadata.html|Built-in - Compiler Metadata
- https://haxe.org/manual/cr-dce.html - Dead Code Elimination