Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

  • ...the performance is bad (especially because of two levels of indirection and the runtime type checks on the Array implementation)
  • ...the code is ugly (since Vector types need to be defined at compiletime I needed a factory returning concrete Vector instances based on an Enum that contains only the supported types)

I'm currently looking into Haxe as a possible solution since it supports type parameters and is able to compile to various Flash Player versions (and apparently compiles into mmore optimized bytecode).

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

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

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

The basic idea is that I want to provide the type information at runtime and get a typesafe Flash Player version independent "collection" for use in the calling code without having to bother with conditional compilation fragments all over the place.

Can Haxe do something like that and if yes, how can I make it work?

like image 278
Baelnorn Avatar asked May 23 '11 12:05

Baelnorn


1 Answers

There's an opportunity in Haxe to override native classes (e.g. int) in Haxe. take a look at the Metadata manual. Metadata has been added in version 2.06.

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

like image 93
Eugeny89 Avatar answered Oct 18 '22 21:10

Eugeny89