Google Groups

Re: Suggestions to simplify the use of flash.Vectors?


Hugh Mar 23, 2012 6:35 PM
Posted in group: Haxe
Joshua,
I was thinking it might be good to have a generic "bucket" nme helper
class for compatibility reasons.
You could put vector in there, but also inject routines to help with
problems of RGBA on neko without the thirty-second bit.
ie, add BitmapData.create that take (rgb:Int, a:Int).

so you would just "import nme.Helpers" or "nme.Compat"

I also can't see where you would "use" a class without "importing" it
- so might be a good shorthand.

Hugh

On Mar 24, 6:26 am, "Joshua Granick" <bulkm...@joshuagranick.com>
wrote:
> Thanks! I didn't think of Class<>
>
> That was almost it. This works:
>
> typedef Vector<T> = Array<T>;
>
> class VectorHelper
> {
>
>         public static inline function ofArray<T>(v:Class<Vector<Dynamic>>,
> array:Array<T>):Vector<T>
>         {
>                 return array;
>         }
>
> }
>
> This really helps.
>
> Is there a way to implement this kind of functionality without requiring
> "using nme.Vector"?
>
> It would be great if this were added automatically when you imported the
> nme.Vector class
>
> On Fri, 23 Mar 2012 13:55:46 -0700, Heinz Hölzer
>
>
>
>
>
>
>
> <heinz.hoel...@googlemail.com> wrote:
>
> > How about:
>
> > class VectorHelper {
>
> >          public static inline function ofArray (v:Class<Vector<T>>,
> > a:Array<T>):Vector<T> {
>
> >              return cast a;
>
> >          }
>
> >      }
>
> > Am 23.03.2012 21:45, schrieb Joshua Granick:
> >> The flash.Vector class is a bother.
>
> >> You can't use a normal cast...
>
> >>     var vertices = cast ([1, 2, 3, 4], Vector<Int>);
>
> >> ...because the type parameter has to be dynamic.
>
> >> You can't use a generic cast...
>
> >>     var vertices:Vector<Int> = cast [1, 2, 3, 4];
>
> >> ... because these are separate types at runtime in Flash.
>
> >> You can use Vector.ofArray...
>
> >>     var vertices = Vector.ofArray ([1, 2, 3, 4]);
>
> >> ...but now you can't use it with other NME targets.
>
> >> NME uses a typedef to make nme.Vector<T> the same as Array<T>
>
> >> You can't extend Array<T>...
>
> >>     class Vector<T> extends Array<T>
>
> >> ...because basic types (like Array) can't be extended
>
> >> You can't create a new data type...
>
> >>     class Vector<T> implements ArrayAccess<T>
>
> >> ...because ArrayAccess<T> won't actually be supported on the target
> >> platform for the new type
>
> >> You can't add a "using" mix-in...
>
> >>     class VectorHelper {
>
> >>         static function ofArray (v:Vector<T>, a:Array<T>):Vector<T> {
>
> >>             return a;
>
> >>         }
>
> >>     }
>
> >> ...because this would work on vector instances, not the static Vector
> >> class
>
> >> So how do we cleanly implement an API that requires the Vector type?
>
> >> It would be wonderful to have a nice solution that doesn't require
> >> conditional code, or some kind of VectorUtils class