Is it possible to write an AS3 library using Haxe that uses type parameters?

First, a little: I'm looking for a way to create a “collection” library that abstracts an implementation based on the version of Flash Player (Vector on FP10, Array on FP9) away from the calling code. I already wrote a small AS3 lib, but ...

  • ... performance is bad (especially because of two levels of indirection and checking the type of runtime in the array implementation).
  • ... the code is ugly (since Vector types must be defined in compiletime I need a factory returning specific Vector instances based on Enum, which contains only supported types)

I am currently considering Haxe as a possible solution, as it supports type parameters and is able to compile various versions of Flash Player (and apparently compiles to mmore optimized bytecode).

Now, my question is: is there a way to write a library in Haxe that can be used as in AS3 code.

var foo:IMyInterface = new MyImplementation(int); var bar:IMyInterface = new MyImplementation(getDefinitionByName("my.package.MyClass")); 

with IMyInterface , exposing the necessary methods ( push , pop , ...)?

The main idea is that I want to provide type information at runtime and get an independent “collection” for the virtualized version of Flash Player for use in the calling code without having to worry about conditional compilation fragments everywhere.

Can Haxe do something like this, and if so, how can I make it work?

+6
source share
1 answer

Haxe now has the ability to override its own classes (for example, int ) in Haxe. see the Metadata Guide . Metadata was added in version 2.06.

As for the analogue of the getDefinitionByName() method. Take a look at the resolveClass() method of the Type class.

+3
source

Source: https://habr.com/ru/post/888812/


All Articles