Overloading External Class Constructor's

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Overloading External Class Constructor's

jamesbjackson
Hi Everyone,

This morning I managed to free up sometime to work on a update to Standard JavaScript and have run into a compiler issues which I not sure if there is a way I can get around it..
I got the following external class for Typed Array's in JavaScript which I am matching exactly to the WebGL specification.

extern class Int8Array implements ArrayBufferView, implements ArrayAccess<Int> {
       
        static var BYTES_PER_ELEMENT:UnsignedLong;
        var buffer(default,null):ArrayBuffer;
        var byteOffset(default,null):UnsignedLong;
        var byteLength(default,null):UnsignedLong;
       
        @:overload(function new(length:UnsignedLong):Void{})
        @:overload(function new(array:Int8Array):Void{})
        @:overload(function new(array:ArrayAccess<Int>):Void{})
        function new(buffer:ArrayBuffer, ?byteOffset:UnsignedLong, ?length:UnsignedLong):Void;
       
        function get(index:UnsignedLong):Int;
        function subarray(begin:Long, end:Long):Int8Array;
       
        @:overload(function set(index:UnsignedLong, value:ArrayAccess<Int>):Void{})
        @:overload(function set(array:Int8Array, ?offset:UnsignedLong):Void{})
        function set(array:ArrayBuffer, ?offset:UnsignedLong):Void;
       
}


Now when I attempt to compile this I just get the "Unexpected new" compiler error? Is there way to allow for overloading external constructor's or am I missing something? If I comment out the overloads it compiles just fine.

James



--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Overloading External Class Constructor's

Andreas Mokros
Hi.

On Mon, 31 Oct 2011 10:44:46 +0000
James Jackson <[hidden email]> wrote:
> Is there way to allow for overloading external constructor's or am I
> missing something?

I think it should look like this:
@:overload(function(length:UnsignedLong):Void{})
@:overload(function(array:Int8Array):Void{})
@:overload(function(array:ArrayAccess<Int>):Void{})
function
new(buffer:ArrayBuffer, ?byteOffset:UnsignedLong, ?length:UnsignedLong):Void;

No "new" in the @:overload().
That's the way it is done in the JQuery externs at least...

--
Mockey

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Overloading External Class Constructor's

jamesbjackson
Thanks Andreas :-)

Thought it was something simple :-) I so love the HaXe community..

James