Sync changes with hxtypedarray repository

This commit is contained in:
Joshua Granick
2015-07-06 17:45:49 -07:00
parent ee08c8c37e
commit bddce4f987
11 changed files with 212 additions and 37 deletions

View File

@@ -239,6 +239,27 @@ class ArrayBufferView {
}
#if !no_typedarray_inline inline #end
function toString() {
var name =
switch(type) {
case Int8: 'Int8Array';
case Uint8: 'UInt8Array';
case Uint8Clamped: 'UInt8ClampedArray';
case Int16: 'Int16Array';
case Uint16: 'UInt16Array';
case Int32: 'Int32Array';
case Uint32: 'UInt32Array';
case Float32: 'Float32Array';
case Float64: 'Float64Array';
case _: 'ArrayBufferView';
}
return name + ' [byteLength:${this.byteLength}, length:${this.length}]';
} //toString
#if !no_typedarray_inline inline #end
function toByteLength( elemCount:Int ) : Int {

View File

@@ -2,7 +2,102 @@ package lime.utils;
#if (js && !display)
typedef DataView = js.html.DataView;
@:forward
abstract DataView(js.html.DataView)
from js.html.DataView
to js.html.DataView {
public inline function new( buffer:ArrayBuffer, byteOffset:Null<Int> = null, byteLength:Null<Int> = null ) {
if(byteOffset != null && byteLength == null) this = new js.html.DataView( buffer, byteOffset );
else if(byteOffset != null && byteLength != null) this = new js.html.DataView( buffer, byteOffset, byteLength);
else this = new js.html.DataView( buffer );
}
#if !no_typedarray_inline inline #end
public function getInt8( byteOffset:Int ) : Int {
return this.getInt8( byteOffset);
}
#if !no_typedarray_inline inline #end
public function getInt16( byteOffset:Int, ?littleEndian:Bool = true ) : Int {
return this.getInt16( byteOffset, littleEndian);
}
#if !no_typedarray_inline inline #end
public function getInt32( byteOffset:Int, ?littleEndian:Bool = true ) : Int {
return this.getInt32( byteOffset, littleEndian);
}
#if !no_typedarray_inline inline #end
public function getUint8( byteOffset:Int ) : UInt {
return this.getUint8( byteOffset);
}
#if !no_typedarray_inline inline #end
public function getUint16( byteOffset:Int, ?littleEndian:Bool = true ) : UInt {
return this.getUint16( byteOffset, littleEndian);
}
#if !no_typedarray_inline inline #end
public function getUint32( byteOffset:Int, ?littleEndian:Bool = true ) : UInt {
return this.getUint32( byteOffset, littleEndian);
}
#if !no_typedarray_inline inline #end
public function getFloat32( byteOffset:Int, ?littleEndian:Bool = true ) : Float {
return this.getFloat32( byteOffset, littleEndian);
}
#if !no_typedarray_inline inline #end
public function getFloat64( byteOffset:Int, ?littleEndian:Bool = true ) : Float {
return this.getFloat64( byteOffset, littleEndian);
}
#if !no_typedarray_inline inline #end
public function setInt8( byteOffset:Int, value:Int ) {
this.setInt8( byteOffset, value);
}
#if !no_typedarray_inline inline #end
public function setInt16( byteOffset:Int, value:Int, ?littleEndian:Bool = true) {
this.setInt16( byteOffset, value, littleEndian);
}
#if !no_typedarray_inline inline #end
public function setInt32( byteOffset:Int, value:Int, ?littleEndian:Bool = true) {
this.setInt32( byteOffset, value, littleEndian);
}
#if !no_typedarray_inline inline #end
public function setUint8( byteOffset:Int, value:UInt ) {
this.setUint8( byteOffset, value);
}
#if !no_typedarray_inline inline #end
public function setUint16( byteOffset:Int, value:UInt, ?littleEndian:Bool = true) {
this.setUint16( byteOffset, value, littleEndian);
}
#if !no_typedarray_inline inline #end
public function setUint32( byteOffset:Int, value:UInt, ?littleEndian:Bool = true) {
this.setUint32( byteOffset, value, littleEndian);
}
#if !no_typedarray_inline inline #end
public function setFloat32( byteOffset:Int, value:Float, ?littleEndian:Bool = true) {
this.setFloat32( byteOffset, value, littleEndian);
}
#if !no_typedarray_inline inline #end
public function setFloat64( byteOffset:Int, value:Float, ?littleEndian:Bool = true) {
this.setFloat64( byteOffset, value, littleEndian);
}
}
#else

View File

@@ -24,10 +24,11 @@ package lime.utils;
} else if(view != null) {
this = new js.html.Float32Array( untyped view );
} else if(buffer != null) {
if (len == null)
if(len == null) {
this = new js.html.Float32Array( buffer, byteoffset );
else
} else {
this = new js.html.Float32Array( buffer, byteoffset, len );
}
} else {
this = null;
}
@@ -39,6 +40,8 @@ package lime.utils;
//non spec haxe conversions
public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int=0, ?len:Int ) : Float32Array {
if(byteOffset == null) return new js.html.Float32Array(cast bytes.getData());
if(len == null) return new js.html.Float32Array(cast bytes.getData(), byteOffset);
return new js.html.Float32Array(cast bytes.getData(), byteOffset, len);
}
@@ -50,6 +53,8 @@ package lime.utils;
#end
}
function toString() return 'Float32Array [byteLength:${this.byteLength}, length:${this.length}]';
}
#else
@@ -102,6 +107,8 @@ abstract Float32Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView {
//Internal
function toString() return 'Float32Array [byteLength:${this.byteLength}, length:${this.length}]';
inline function get_length() return this.length;

View File

@@ -24,10 +24,11 @@ package lime.utils;
} else if(view != null) {
this = new js.html.Float64Array( untyped view );
} else if(buffer != null) {
if (len == null)
if(len == null) {
this = new js.html.Float64Array( buffer, byteoffset );
else
} else {
this = new js.html.Float64Array( buffer, byteoffset, len );
}
} else {
this = null;
}
@@ -39,6 +40,8 @@ package lime.utils;
//non spec haxe conversions
public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int=0, ?len:Int ) : Float64Array {
if(byteOffset == null) return new js.html.Float64Array(cast bytes.getData());
if(len == null) return new js.html.Float64Array(cast bytes.getData(), byteOffset);
return new js.html.Float64Array(cast bytes.getData(), byteOffset, len);
}
@@ -50,6 +53,8 @@ package lime.utils;
#end
}
function toString() return 'Float64Array [byteLength:${this.byteLength}, length:${this.length}]';
}
#else
@@ -116,6 +121,8 @@ abstract Float64Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView {
return ArrayBufferIO.setFloat64(this.buffer, this.byteOffset+(idx*BYTES_PER_ELEMENT), val);
}
function toString() return 'Float64Array [byteLength:${this.byteLength}, length:${this.length}]';
}
#end //!js

View File

@@ -24,10 +24,11 @@ package lime.utils;
} else if(view != null) {
this = new js.html.Int16Array( untyped view );
} else if(buffer != null) {
if (len == null)
if(len == null) {
this = new js.html.Int16Array( buffer, byteoffset );
else
} else {
this = new js.html.Int16Array( buffer, byteoffset, len );
}
} else {
this = null;
}
@@ -39,6 +40,8 @@ package lime.utils;
//non spec haxe conversions
public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int=0, ?len:Int ) : Int16Array {
if(byteOffset == null) return new js.html.Int16Array(cast bytes.getData());
if(len == null) return new js.html.Int16Array(cast bytes.getData(), byteOffset);
return new js.html.Int16Array(cast bytes.getData(), byteOffset, len);
}
@@ -50,6 +53,8 @@ package lime.utils;
#end
}
function toString() return 'Int16Array [byteLength:${this.byteLength}, length:${this.length}]';
}
#else
@@ -116,6 +121,8 @@ abstract Int16Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView {
return ArrayBufferIO.setInt16(this.buffer, this.byteOffset+(idx*BYTES_PER_ELEMENT), val);
}
function toString() return 'Int16Array [byteLength:${this.byteLength}, length:${this.length}]';
}
#end //!js

View File

@@ -24,10 +24,11 @@ package lime.utils;
} else if(view != null) {
this = new js.html.Int32Array( untyped view );
} else if(buffer != null) {
if (len == null)
if(len == null) {
this = new js.html.Int32Array( buffer, byteoffset );
else
} else {
this = new js.html.Int32Array( buffer, byteoffset, len );
}
} else {
this = null;
}
@@ -39,6 +40,8 @@ package lime.utils;
//non spec haxe conversions
public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int=0, ?len:Int ) : Int32Array {
if(byteOffset == null) return new js.html.Int32Array(cast bytes.getData());
if(len == null) return new js.html.Int32Array(cast bytes.getData(), byteOffset);
return new js.html.Int32Array(cast bytes.getData(), byteOffset, len);
}
@@ -50,13 +53,14 @@ package lime.utils;
#end
}
function toString() return 'Int32Array [byteLength:${this.byteLength}, length:${this.length}]';
}
#else
import lime.utils.ArrayBufferView;
@:forward()
@:arrayAccess
abstract Int32Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView {
@@ -117,6 +121,8 @@ abstract Int32Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView {
return ArrayBufferIO.setInt32(this.buffer, this.byteOffset+(idx*BYTES_PER_ELEMENT), val);
}
function toString() return 'Int32Array [byteLength:${this.byteLength}, length:${this.length}]';
}
#end //!js

View File

@@ -24,10 +24,11 @@ package lime.utils;
} else if(view != null) {
this = new js.html.Int8Array( untyped view );
} else if(buffer != null) {
if (len == null)
if(len == null) {
this = new js.html.Int8Array( buffer, byteoffset );
else
} else {
this = new js.html.Int8Array( buffer, byteoffset, len );
}
} else {
this = null;
}
@@ -50,6 +51,8 @@ package lime.utils;
#end
}
function toString() return 'Int8Array [byteLength:${this.byteLength}, length:${this.length}]';
}
#else
@@ -92,7 +95,9 @@ abstract Int8Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView {
//non spec haxe conversions
public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int=0, ?len:Int ) : Int8Array {
return new Int8Array(bytes, byteOffset, len);
if(byteOffset == null) return new Int8Array(cast bytes.getData());
if(len == null) return new Int8Array(cast bytes.getData(), byteOffset);
return new Int8Array(cast bytes.getData(), byteOffset, len);
}
public function toBytes() : haxe.io.Bytes {
@@ -116,6 +121,8 @@ abstract Int8Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView {
return ArrayBufferIO.setInt8(this.buffer, this.byteOffset+idx, val);
}
function toString() return 'Int8Array [byteLength:${this.byteLength}, length:${this.length}]';
}
#end //!js

View File

@@ -24,10 +24,11 @@ package lime.utils;
} else if(view != null) {
this = new js.html.Uint16Array( untyped view );
} else if(buffer != null) {
if (len == null)
if(len == null) {
this = new js.html.Uint16Array( buffer, byteoffset );
else
} else {
this = new js.html.Uint16Array( buffer, byteoffset, len );
}
} else {
this = null;
}
@@ -39,6 +40,8 @@ package lime.utils;
//non spec haxe conversions
public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int=0, ?len:Int ) : UInt16Array {
if(byteOffset == null) return new js.html.Uint16Array(cast bytes.getData());
if(len == null) return new js.html.Uint16Array(cast bytes.getData(), byteOffset);
return new js.html.Uint16Array(cast bytes.getData(), byteOffset, len);
}
@@ -50,6 +53,8 @@ package lime.utils;
#end
}
function toString() return 'UInt16Array [byteLength:${this.byteLength}, length:${this.length}]';
}
#else
@@ -91,7 +96,7 @@ abstract UInt16Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView {
//non spec haxe conversions
public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int=0, ?len:Int ) : UInt16Array {
public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int=0, ?len:Int ) : Uint16Array {
return new UInt16Array(bytes, byteOffset, len);
}
@@ -116,6 +121,8 @@ abstract UInt16Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView {
return ArrayBufferIO.setUint16(this.buffer, this.byteOffset+(idx*BYTES_PER_ELEMENT), val);
}
function toString() return 'UInt16Array [byteLength:${this.byteLength}, length:${this.length}]';
}
#end //!js

View File

@@ -24,10 +24,11 @@ package lime.utils;
} else if(view != null) {
this = new js.html.Uint32Array( untyped view );
} else if(buffer != null) {
if (len == null)
if(len == null) {
this = new js.html.Uint32Array( buffer, byteoffset );
else
} else {
this = new js.html.Uint32Array( buffer, byteoffset, len );
}
} else {
this = null;
}
@@ -39,6 +40,8 @@ package lime.utils;
//non spec haxe conversions
public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int=0, ?len:Int ) : UInt32Array {
if(byteOffset == null) return new js.html.Uint32Array(cast bytes.getData());
if(len == null) return new js.html.Uint32Array(cast bytes.getData(), byteOffset);
return new js.html.Uint32Array(cast bytes.getData(), byteOffset, len);
}
@@ -50,6 +53,8 @@ package lime.utils;
#end
}
function toString() return 'UInt32Array [byteLength:${this.byteLength}, length:${this.length}]';
}
#else
@@ -116,6 +121,8 @@ abstract UInt32Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView {
return ArrayBufferIO.setUint32(this.buffer, this.byteOffset+(idx*BYTES_PER_ELEMENT), val);
}
function toString() return 'UInt32Array [byteLength:${this.byteLength}, length:${this.length}]';
}
#end //!js

View File

@@ -24,10 +24,11 @@ package lime.utils;
} else if(view != null) {
this = new js.html.Uint8Array( untyped view );
} else if(buffer != null) {
if (len == null)
if(len == null) {
this = new js.html.Uint8Array( buffer, byteoffset );
else
} else {
this = new js.html.Uint8Array( buffer, byteoffset, len );
}
} else {
this = null;
}
@@ -38,7 +39,9 @@ package lime.utils;
//non spec haxe conversions
public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int=0, ?len:Int ) : UInt8Array {
public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int, ?len:Int ) : UInt8Array {
if(byteOffset == null) return new js.html.Uint8Array(cast bytes.getData());
if(len == null) return new js.html.Uint8Array(cast bytes.getData(), byteOffset);
return new js.html.Uint8Array(cast bytes.getData(), byteOffset, len);
}
@@ -50,13 +53,14 @@ package lime.utils;
#end
}
function toString() return 'UInt8Array [byteLength:${this.byteLength}, length:${this.length}]';
}
#else
import lime.utils.ArrayBufferView;
@:forward()
@:arrayAccess
abstract UInt8Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView {
@@ -102,6 +106,8 @@ abstract UInt8Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView {
//Internal
function toString() return 'UInt8Array [byteLength:${this.byteLength}, length:${this.length}]';
inline function get_length() return this.length;

View File

@@ -24,10 +24,11 @@ package lime.utils;
} else if(view != null) {
this = new js.html.Uint8ClampedArray( untyped view );
} else if(buffer != null) {
if (len == null)
if (len == null) {
this = new js.html.Uint8ClampedArray( buffer, byteoffset );
else
} else {
this = new js.html.Uint8ClampedArray( buffer, byteoffset, len );
}
} else {
this = null;
}
@@ -39,6 +40,8 @@ package lime.utils;
//non spec haxe conversions
public static function fromBytes( bytes:haxe.io.Bytes, ?byteOffset:Int=0, ?len:Int ) : UInt8ClampedArray {
if(byteOffset == null) return new js.html.Uint8ClampedArray(cast bytes.getData());
if(len == null) return new js.html.Uint8ClampedArray(cast bytes.getData(), byteOffset);
return new js.html.Uint8ClampedArray(cast bytes.getData(), byteOffset, len);
}
@@ -50,6 +53,8 @@ package lime.utils;
#end
}
function toString() return 'UInt8ClampedArray [byteLength:${this.byteLength}, length:${this.length}]';
//internal
//clamp a Int to a 0-255 Uint8
static function _clamp(_in:Float) : Int {
@@ -64,7 +69,6 @@ package lime.utils;
import lime.utils.ArrayBufferView;
@:forward()
@:arrayAccess
abstract UInt8ClampedArray(ArrayBufferView) from ArrayBufferView to ArrayBufferView {
@@ -125,6 +129,7 @@ abstract UInt8ClampedArray(ArrayBufferView) from ArrayBufferView to ArrayBufferV
return ArrayBufferIO.setUint8Clamped(this.buffer, this.byteOffset+idx, val);
}
function toString() return 'UInt8ClampedArray [byteLength:${this.byteLength}, length:${this.length}]';
}