[build] update publish task
This commit is contained in:
164
src/fixes/haxe/lime/utils/Float32Array.hx
Normal file
164
src/fixes/haxe/lime/utils/Float32Array.hx
Normal file
@@ -0,0 +1,164 @@
|
||||
package lime.utils;
|
||||
|
||||
#if (js && !doc_gen)
|
||||
#if haxe4
|
||||
import js.lib.Float32Array as JSFloat32Array;
|
||||
import js.lib.Uint8Array as JSUInt8Array;
|
||||
#else
|
||||
import js.html.Float32Array as JSFloat32Array;
|
||||
import js.html.Uint8Array as JSUInt8Array;
|
||||
#end
|
||||
@:forward
|
||||
@:arrayAccess
|
||||
abstract Float32Array(JSFloat32Array) from JSFloat32Array to JSFloat32Array/* to ArrayBufferView*/
|
||||
{
|
||||
public inline static var BYTES_PER_ELEMENT:Int = 4;
|
||||
|
||||
@:generic
|
||||
public inline function new<T>(?elements:Int, ?array:Array<T>, #if openfl ?vector:openfl.Vector<Float>, #end ?view:ArrayBufferView, ?buffer:ArrayBuffer,
|
||||
?byteoffset:Int = 0, ?len:Null<Int>)
|
||||
{
|
||||
if (elements != null)
|
||||
{
|
||||
this = new JSFloat32Array(elements);
|
||||
}
|
||||
else if (array != null)
|
||||
{
|
||||
this = new JSFloat32Array(untyped array);
|
||||
#if (openfl && commonjs)
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new JSFloat32Array(untyped (vector));
|
||||
#elseif openfl
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new JSFloat32Array(untyped untyped (vector).__array);
|
||||
#end
|
||||
}
|
||||
else if (view != null)
|
||||
{
|
||||
this = new JSFloat32Array(untyped view);
|
||||
}
|
||||
else if (buffer != null)
|
||||
{
|
||||
if (len == null)
|
||||
{
|
||||
this = new JSFloat32Array(buffer, byteoffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
this = new JSFloat32Array(buffer, byteoffset, len);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this = null;
|
||||
}
|
||||
}
|
||||
|
||||
@:arrayAccess @:extern inline function __set(idx:Int, val:Float):Float
|
||||
return this[idx] = val;
|
||||
|
||||
@:arrayAccess @:extern inline function __get(idx:Int):Float
|
||||
return this[idx];
|
||||
|
||||
// non spec haxe conversions
|
||||
inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):Float32Array
|
||||
{
|
||||
if (byteOffset == null) return new JSFloat32Array(cast bytes.getData());
|
||||
if (len == null) return new JSFloat32Array(cast bytes.getData(), byteOffset);
|
||||
return new JSFloat32Array(cast bytes.getData(), byteOffset, len);
|
||||
}
|
||||
|
||||
inline public function toBytes():haxe.io.Bytes
|
||||
{
|
||||
return @:privateAccess new haxe.io.Bytes(cast new JSUInt8Array(this.buffer));
|
||||
}
|
||||
|
||||
inline function toString()
|
||||
return this != null ? 'Float32Array [byteLength:${this.byteLength}, length:${this.length}]' : null;
|
||||
}
|
||||
#else
|
||||
import lime.utils.ArrayBuffer;
|
||||
import lime.utils.ArrayBufferView;
|
||||
|
||||
@:forward
|
||||
abstract Float32Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView
|
||||
{
|
||||
public inline static var BYTES_PER_ELEMENT:Int = 4;
|
||||
public static var hello:Int;
|
||||
|
||||
public var length(get, never):Int;
|
||||
|
||||
@:generic
|
||||
public inline function new<T>(?elements:Int, ?buffer:ArrayBuffer, ?array:Array<T>, #if openfl ?vector:openfl.Vector<Float>, #end ?view:ArrayBufferView,
|
||||
?byteoffset:Int = 0, ?len:Null<Int>)
|
||||
{
|
||||
if (elements != null)
|
||||
{
|
||||
this = new ArrayBufferView(elements, Float32);
|
||||
}
|
||||
else if (array != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Float32).initArray(array);
|
||||
#if openfl
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Float32).initArray(untyped (vector).__array);
|
||||
#end
|
||||
}
|
||||
else if (view != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Float32).initTypedArray(view);
|
||||
}
|
||||
else if (buffer != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Float32).initBuffer(buffer, byteoffset, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw "Invalid constructor arguments for Float32Array";
|
||||
}
|
||||
}
|
||||
|
||||
// Public API
|
||||
public inline function subarray(begin:Int, end:Null<Int> = null):Float32Array
|
||||
return this.subarray(begin, end);
|
||||
|
||||
// non spec haxe conversions
|
||||
inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):Float32Array
|
||||
{
|
||||
return new Float32Array(bytes, byteOffset, len);
|
||||
}
|
||||
|
||||
inline public function toBytes():haxe.io.Bytes
|
||||
{
|
||||
return this.buffer;
|
||||
}
|
||||
|
||||
// Internal
|
||||
inline function toString()
|
||||
return this != null ? 'Float32Array [byteLength:${this.byteLength}, length:${this.length}]' : null;
|
||||
|
||||
@:extern inline function get_length()
|
||||
return this.length;
|
||||
|
||||
@:noCompletion
|
||||
@:arrayAccess @:extern
|
||||
public inline function __get(idx:Int):Float
|
||||
{
|
||||
return ArrayBufferIO.getFloat32(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT));
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
@:arrayAccess @:extern
|
||||
public inline function __set(idx:Int, val:Float):Float
|
||||
{
|
||||
ArrayBufferIO.setFloat32(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT), val);
|
||||
return val;
|
||||
}
|
||||
}
|
||||
#end // !js
|
||||
161
src/fixes/haxe/lime/utils/Float64Array.hx
Normal file
161
src/fixes/haxe/lime/utils/Float64Array.hx
Normal file
@@ -0,0 +1,161 @@
|
||||
package lime.utils;
|
||||
|
||||
#if (js && !doc_gen)
|
||||
#if haxe4
|
||||
import js.lib.Float64Array as JSFloat64Array;
|
||||
import js.lib.Uint8Array as JSUInt8Array;
|
||||
#else
|
||||
import js.html.Float64Array as JSFloat64Array;
|
||||
import js.html.Uint8Array as JSUInt8Array;
|
||||
#end
|
||||
@:forward
|
||||
abstract Float64Array(JSFloat64Array) from JSFloat64Array to JSFloat64Array/* to ArrayBufferView*/
|
||||
{
|
||||
public inline static var BYTES_PER_ELEMENT:Int = 8;
|
||||
|
||||
@:generic
|
||||
public inline function new<T>(?elements:Int, ?array:Array<T>, #if openfl ?vector:openfl.Vector<Float>, #end ?view:ArrayBufferView, ?buffer:ArrayBuffer,
|
||||
?byteoffset:Int = 0, ?len:Null<Int>)
|
||||
{
|
||||
if (elements != null)
|
||||
{
|
||||
this = new JSFloat64Array(elements);
|
||||
}
|
||||
else if (array != null)
|
||||
{
|
||||
this = new JSFloat64Array(untyped array);
|
||||
#if (openfl && commonjs)
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new JSFloat64Array(untyped (vector));
|
||||
#elseif openfl
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new JSFloat64Array(untyped untyped (vector).__array);
|
||||
#end
|
||||
}
|
||||
else if (view != null)
|
||||
{
|
||||
this = new JSFloat64Array(untyped view);
|
||||
}
|
||||
else if (buffer != null)
|
||||
{
|
||||
if (len == null)
|
||||
{
|
||||
this = new JSFloat64Array(buffer, byteoffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
this = new JSFloat64Array(buffer, byteoffset, len);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this = null;
|
||||
}
|
||||
}
|
||||
|
||||
@:arrayAccess @:extern inline function __set(idx:Int, val:Float):Float
|
||||
return this[idx] = val;
|
||||
|
||||
@:arrayAccess @:extern inline function __get(idx:Int):Float
|
||||
return this[idx];
|
||||
|
||||
// non spec haxe conversions
|
||||
inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):Float64Array
|
||||
{
|
||||
if (byteOffset == null) return new JSFloat64Array(cast bytes.getData());
|
||||
if (len == null) return new JSFloat64Array(cast bytes.getData(), byteOffset);
|
||||
return new JSFloat64Array(cast bytes.getData(), byteOffset, len);
|
||||
}
|
||||
|
||||
inline public function toBytes():haxe.io.Bytes
|
||||
{
|
||||
return @:privateAccess new haxe.io.Bytes(cast new JSUInt8Array(this.buffer));
|
||||
}
|
||||
|
||||
function toString()
|
||||
return this != null ? 'Float64Array [byteLength:${this.byteLength}, length:${this.length}]' : null;
|
||||
}
|
||||
#else
|
||||
import lime.utils.ArrayBufferView;
|
||||
|
||||
@:forward
|
||||
abstract Float64Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView
|
||||
{
|
||||
public inline static var BYTES_PER_ELEMENT:Int = 8;
|
||||
|
||||
public var length(get, never):Int;
|
||||
|
||||
@:generic
|
||||
public inline function new<T>(?elements:Int, ?buffer:ArrayBuffer, ?array:Array<T>, #if openfl ?vector:openfl.Vector<Float>, #end ?view:ArrayBufferView,
|
||||
?byteoffset:Int = 0, ?len:Null<Int>)
|
||||
{
|
||||
if (elements != null)
|
||||
{
|
||||
this = new ArrayBufferView(elements, Float64);
|
||||
}
|
||||
else if (array != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Float64).initArray(array);
|
||||
#if openfl
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Float64).initArray(untyped (vector).__array);
|
||||
#end
|
||||
}
|
||||
else if (view != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Float64).initTypedArray(view);
|
||||
}
|
||||
else if (buffer != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Float64).initBuffer(buffer, byteoffset, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw "Invalid constructor arguments for Float64Array";
|
||||
}
|
||||
}
|
||||
|
||||
// Public API
|
||||
public inline function subarray(begin:Int, end:Null<Int> = null):Float64Array
|
||||
return this.subarray(begin, end);
|
||||
|
||||
// non spec haxe conversions
|
||||
inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):Float64Array
|
||||
{
|
||||
return new Float64Array(bytes, byteOffset, len);
|
||||
}
|
||||
|
||||
inline public function toBytes():haxe.io.Bytes
|
||||
{
|
||||
return this.buffer;
|
||||
}
|
||||
|
||||
// Internal
|
||||
inline function get_length()
|
||||
return this.length;
|
||||
|
||||
@:noCompletion
|
||||
@:arrayAccess @:extern
|
||||
public inline function __get(idx:Int):Float
|
||||
{
|
||||
return ArrayBufferIO.getFloat64(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT));
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
@:arrayAccess @:extern
|
||||
public inline function __set(idx:Int, val:Float):Float
|
||||
{
|
||||
ArrayBufferIO.setFloat64(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT), val);
|
||||
return val;
|
||||
}
|
||||
|
||||
inline function toString()
|
||||
return this != null ? 'Float64Array [byteLength:${this.byteLength}, length:${this.length}]' : null;
|
||||
}
|
||||
#end // !js
|
||||
161
src/fixes/haxe/lime/utils/Int16Array.hx
Normal file
161
src/fixes/haxe/lime/utils/Int16Array.hx
Normal file
@@ -0,0 +1,161 @@
|
||||
package lime.utils;
|
||||
|
||||
#if (js && !doc_gen)
|
||||
#if haxe4
|
||||
import js.lib.Int16Array as JSInt16Array;
|
||||
import js.lib.Uint8Array as JSUInt8Array;
|
||||
#else
|
||||
import js.html.Int16Array as JSInt16Array;
|
||||
import js.html.Uint8Array as JSUInt8Array;
|
||||
#end
|
||||
@:forward
|
||||
abstract Int16Array(JSInt16Array) from JSInt16Array to JSInt16Array/* to ArrayBufferView*/
|
||||
{
|
||||
public inline static var BYTES_PER_ELEMENT:Int = 2;
|
||||
|
||||
@:generic
|
||||
public inline function new<T>(?elements:Int, ?array:Array<T>, #if openfl ?vector:openfl.Vector<Int>, #end ?view:ArrayBufferView, ?buffer:ArrayBuffer,
|
||||
?byteoffset:Int = 0, ?len:Null<Int>)
|
||||
{
|
||||
if (elements != null)
|
||||
{
|
||||
this = new JSInt16Array(elements);
|
||||
}
|
||||
else if (array != null)
|
||||
{
|
||||
this = new JSInt16Array(untyped array);
|
||||
#if (openfl && commonjs)
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new JSInt16Array(untyped (vector));
|
||||
#elseif openfl
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new JSInt16Array(untyped untyped (vector).__array);
|
||||
#end
|
||||
}
|
||||
else if (view != null)
|
||||
{
|
||||
this = new JSInt16Array(untyped view);
|
||||
}
|
||||
else if (buffer != null)
|
||||
{
|
||||
if (len == null)
|
||||
{
|
||||
this = new JSInt16Array(buffer, byteoffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
this = new JSInt16Array(buffer, byteoffset, len);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this = null;
|
||||
}
|
||||
}
|
||||
|
||||
@:arrayAccess @:extern inline function __set(idx:Int, val:Int):Int
|
||||
return this[idx] = val;
|
||||
|
||||
@:arrayAccess @:extern inline function __get(idx:Int):Int
|
||||
return this[idx];
|
||||
|
||||
// non spec haxe conversions
|
||||
inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):Int16Array
|
||||
{
|
||||
if (byteOffset == null) return new JSInt16Array(cast bytes.getData());
|
||||
if (len == null) return new JSInt16Array(cast bytes.getData(), byteOffset);
|
||||
return new JSInt16Array(cast bytes.getData(), byteOffset, len);
|
||||
}
|
||||
|
||||
inline public function toBytes():haxe.io.Bytes
|
||||
{
|
||||
return @:privateAccess new haxe.io.Bytes(cast new JSUInt8Array(this.buffer));
|
||||
}
|
||||
|
||||
inline function toString()
|
||||
return this != null ? 'Int16Array [byteLength:${this.byteLength}, length:${this.length}]' : null;
|
||||
}
|
||||
#else
|
||||
import lime.utils.ArrayBufferView;
|
||||
|
||||
@:forward
|
||||
abstract Int16Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView
|
||||
{
|
||||
public inline static var BYTES_PER_ELEMENT:Int = 2;
|
||||
|
||||
public var length(get, never):Int;
|
||||
|
||||
@:generic
|
||||
public inline function new<T>(?elements:Int, ?buffer:ArrayBuffer, ?array:Array<T>, #if openfl ?vector:openfl.Vector<Int>, #end ?view:ArrayBufferView,
|
||||
?byteoffset:Int = 0, ?len:Null<Int>)
|
||||
{
|
||||
if (elements != null)
|
||||
{
|
||||
this = new ArrayBufferView(elements, Int16);
|
||||
}
|
||||
else if (array != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Int16).initArray(array);
|
||||
#if openfl
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Int16).initArray(untyped (vector).__array);
|
||||
#end
|
||||
}
|
||||
else if (view != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Int16).initTypedArray(view);
|
||||
}
|
||||
else if (buffer != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Int16).initBuffer(buffer, byteoffset, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw "Invalid constructor arguments for Int16Array";
|
||||
}
|
||||
}
|
||||
|
||||
// Public API
|
||||
public inline function subarray(begin:Int, end:Null<Int> = null):Int16Array
|
||||
return this.subarray(begin, end);
|
||||
|
||||
// non spec haxe conversions
|
||||
inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):Int16Array
|
||||
{
|
||||
return new Int16Array(bytes, byteOffset, len);
|
||||
}
|
||||
|
||||
inline public function toBytes():haxe.io.Bytes
|
||||
{
|
||||
return this.buffer;
|
||||
}
|
||||
|
||||
// Internal
|
||||
inline function get_length()
|
||||
return this.length;
|
||||
|
||||
@:noCompletion
|
||||
@:arrayAccess @:extern
|
||||
public inline function __get(idx:Int)
|
||||
{
|
||||
return ArrayBufferIO.getInt16(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT));
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
@:arrayAccess @:extern
|
||||
public inline function __set(idx:Int, val:Int)
|
||||
{
|
||||
ArrayBufferIO.setInt16(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT), val);
|
||||
return val;
|
||||
}
|
||||
|
||||
inline function toString()
|
||||
return this != null ? 'Int16Array [byteLength:${this.byteLength}, length:${this.length}]' : null;
|
||||
}
|
||||
#end // !js
|
||||
161
src/fixes/haxe/lime/utils/Int32Array.hx
Normal file
161
src/fixes/haxe/lime/utils/Int32Array.hx
Normal file
@@ -0,0 +1,161 @@
|
||||
package lime.utils;
|
||||
|
||||
#if (js && !doc_gen)
|
||||
#if haxe4
|
||||
import js.lib.Int32Array as JSInt32Array;
|
||||
import js.lib.Uint8Array as JSUInt8Array;
|
||||
#else
|
||||
import js.html.Int32Array as JSInt32Array;
|
||||
import js.html.Uint8Array as JSUInt8Array;
|
||||
#end
|
||||
@:forward
|
||||
abstract Int32Array(JSInt32Array) from JSInt32Array to JSInt32Array/* to ArrayBufferView*/
|
||||
{
|
||||
public inline static var BYTES_PER_ELEMENT:Int = 4;
|
||||
|
||||
@:generic
|
||||
public inline function new<T>(?elements:Int, ?array:Array<T>, #if openfl ?vector:openfl.Vector<Int>, #end ?view:ArrayBufferView, ?buffer:ArrayBuffer,
|
||||
?byteoffset:Int = 0, ?len:Null<Int>)
|
||||
{
|
||||
if (elements != null)
|
||||
{
|
||||
this = new JSInt32Array(elements);
|
||||
}
|
||||
else if (array != null)
|
||||
{
|
||||
this = new JSInt32Array(untyped array);
|
||||
#if (openfl && commonjs)
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new JSInt32Array(untyped (vector));
|
||||
#elseif openfl
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new JSInt32Array(untyped untyped (vector).__array);
|
||||
#end
|
||||
}
|
||||
else if (view != null)
|
||||
{
|
||||
this = new JSInt32Array(untyped view);
|
||||
}
|
||||
else if (buffer != null)
|
||||
{
|
||||
if (len == null)
|
||||
{
|
||||
this = new JSInt32Array(buffer, byteoffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
this = new JSInt32Array(buffer, byteoffset, len);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this = null;
|
||||
}
|
||||
}
|
||||
|
||||
@:arrayAccess @:extern inline function __set(idx:Int, val:Int):Int
|
||||
return this[idx] = val;
|
||||
|
||||
@:arrayAccess @:extern inline function __get(idx:Int):Int
|
||||
return this[idx];
|
||||
|
||||
// non spec haxe conversions
|
||||
inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):Int32Array
|
||||
{
|
||||
if (byteOffset == null) return new JSInt32Array(cast bytes.getData());
|
||||
if (len == null) return new JSInt32Array(cast bytes.getData(), byteOffset);
|
||||
return new JSInt32Array(cast bytes.getData(), byteOffset, len);
|
||||
}
|
||||
|
||||
inline public function toBytes():haxe.io.Bytes
|
||||
{
|
||||
return @:privateAccess new haxe.io.Bytes(cast new JSUInt8Array(this.buffer));
|
||||
}
|
||||
|
||||
inline function toString()
|
||||
return this != null ? 'Int32Array [byteLength:${this.byteLength}, length:${this.length}]' : null;
|
||||
}
|
||||
#else
|
||||
import lime.utils.ArrayBufferView;
|
||||
|
||||
@:forward
|
||||
abstract Int32Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView
|
||||
{
|
||||
public inline static var BYTES_PER_ELEMENT:Int = 4;
|
||||
|
||||
public var length(get, never):Int;
|
||||
|
||||
@:generic
|
||||
public inline function new<T>(?elements:Int, ?buffer:ArrayBuffer, ?array:Array<T>, #if openfl ?vector:openfl.Vector<Int>, #end ?view:ArrayBufferView,
|
||||
?byteoffset:Int = 0, ?len:Null<Int>)
|
||||
{
|
||||
if (elements != null)
|
||||
{
|
||||
this = new ArrayBufferView(elements, Int32);
|
||||
}
|
||||
else if (array != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Int32).initArray(array);
|
||||
#if openfl
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Int32).initArray(untyped (vector).__array);
|
||||
#end
|
||||
}
|
||||
else if (view != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Int32).initTypedArray(view);
|
||||
}
|
||||
else if (buffer != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Int32).initBuffer(buffer, byteoffset, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw "Invalid constructor arguments for Int32Array";
|
||||
}
|
||||
}
|
||||
|
||||
// Public API
|
||||
public inline function subarray(begin:Int, end:Null<Int> = null):Int32Array
|
||||
return this.subarray(begin, end);
|
||||
|
||||
// non spec haxe conversions
|
||||
inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):Int32Array
|
||||
{
|
||||
return new Int32Array(bytes, byteOffset, len);
|
||||
}
|
||||
|
||||
inline public function toBytes():haxe.io.Bytes
|
||||
{
|
||||
return this.buffer;
|
||||
}
|
||||
|
||||
// Internal
|
||||
inline function get_length()
|
||||
return this.length;
|
||||
|
||||
@:noCompletion
|
||||
@:arrayAccess @:extern
|
||||
public inline function __get(idx:Int)
|
||||
{
|
||||
return ArrayBufferIO.getInt32(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT));
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
@:arrayAccess @:extern
|
||||
public inline function __set(idx:Int, val:Int)
|
||||
{
|
||||
ArrayBufferIO.setInt32(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT), val);
|
||||
return val;
|
||||
}
|
||||
|
||||
inline function toString()
|
||||
return this != null ? 'Int32Array [byteLength:${this.byteLength}, length:${this.length}]' : null;
|
||||
}
|
||||
#end // !js
|
||||
161
src/fixes/haxe/lime/utils/Int8Array.hx
Normal file
161
src/fixes/haxe/lime/utils/Int8Array.hx
Normal file
@@ -0,0 +1,161 @@
|
||||
package lime.utils;
|
||||
|
||||
#if (js && !doc_gen)
|
||||
#if haxe4
|
||||
import js.lib.Int8Array as JSInt8Array;
|
||||
import js.lib.Uint8Array as JSUInt8Array;
|
||||
#else
|
||||
import js.html.Int8Array as JSInt8Array;
|
||||
import js.html.Uint8Array as JSUInt8Array;
|
||||
#end
|
||||
@:forward
|
||||
abstract Int8Array(JSInt8Array) from JSInt8Array to JSInt8Array/* to ArrayBufferView*/
|
||||
{
|
||||
public inline static var BYTES_PER_ELEMENT:Int = 1;
|
||||
|
||||
@:generic
|
||||
public inline function new<T>(?elements:Int, ?array:Array<T>, #if openfl ?vector:openfl.Vector<Int>, #end ?view:ArrayBufferView, ?buffer:ArrayBuffer,
|
||||
?byteoffset:Int = 0, ?len:Null<Int>)
|
||||
{
|
||||
if (elements != null)
|
||||
{
|
||||
this = new JSInt8Array(elements);
|
||||
}
|
||||
else if (array != null)
|
||||
{
|
||||
this = new JSInt8Array(untyped array);
|
||||
#if (openfl && commonjs)
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new JSInt8Array(untyped (vector));
|
||||
#elseif openfl
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new JSInt8Array(untyped untyped (vector).__array);
|
||||
#end
|
||||
}
|
||||
else if (view != null)
|
||||
{
|
||||
this = new JSInt8Array(untyped view);
|
||||
}
|
||||
else if (buffer != null)
|
||||
{
|
||||
if (len == null)
|
||||
{
|
||||
this = new JSInt8Array(buffer, byteoffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
this = new JSInt8Array(buffer, byteoffset, len);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this = null;
|
||||
}
|
||||
}
|
||||
|
||||
@:arrayAccess @:extern inline function __set(idx:Int, val:Int):Int
|
||||
return this[idx] = val;
|
||||
|
||||
@:arrayAccess @:extern inline function __get(idx:Int):Int
|
||||
return this[idx];
|
||||
|
||||
// non spec haxe conversions
|
||||
inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):Int8Array
|
||||
{
|
||||
return new JSInt8Array(cast bytes.getData(), byteOffset, len);
|
||||
}
|
||||
|
||||
inline public function toBytes():haxe.io.Bytes
|
||||
{
|
||||
return @:privateAccess new haxe.io.Bytes(cast new JSUInt8Array(this.buffer));
|
||||
}
|
||||
|
||||
inline function toString()
|
||||
return this != null ? 'Int8Array [byteLength:${this.byteLength}, length:${this.length}]' : null;
|
||||
}
|
||||
#else
|
||||
import lime.utils.ArrayBufferView;
|
||||
|
||||
@:forward
|
||||
abstract Int8Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView
|
||||
{
|
||||
public inline static var BYTES_PER_ELEMENT:Int = 1;
|
||||
|
||||
public var length(get, never):Int;
|
||||
|
||||
@:generic
|
||||
public inline function new<T>(?elements:Int, ?buffer:ArrayBuffer, ?array:Array<T>, #if openfl ?vector:openfl.Vector<Int>, #end ?view:ArrayBufferView,
|
||||
?byteoffset:Int = 0, ?len:Null<Int>)
|
||||
{
|
||||
if (elements != null)
|
||||
{
|
||||
this = new ArrayBufferView(elements, Int8);
|
||||
}
|
||||
else if (array != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Int8).initArray(array);
|
||||
#if openfl
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Int8).initArray(untyped (vector).__array);
|
||||
#end
|
||||
}
|
||||
else if (view != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Int8).initTypedArray(view);
|
||||
}
|
||||
else if (buffer != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Int8).initBuffer(buffer, byteoffset, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw "Invalid constructor arguments for Int8Array";
|
||||
}
|
||||
}
|
||||
|
||||
// Public API
|
||||
public inline function subarray(begin:Int, end:Null<Int> = null):Int8Array
|
||||
return this.subarray(begin, end);
|
||||
|
||||
// non spec haxe conversions
|
||||
inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):Int8Array
|
||||
{
|
||||
if (byteOffset == null) return new Int8Array(null, null, cast bytes.getData());
|
||||
if (len == null) return new Int8Array(null, null, cast bytes.getData(), byteOffset);
|
||||
return new Int8Array(null, null, cast bytes.getData(), byteOffset, len);
|
||||
}
|
||||
|
||||
inline public function toBytes():haxe.io.Bytes
|
||||
{
|
||||
return this.buffer;
|
||||
}
|
||||
|
||||
// Internal
|
||||
inline function get_length()
|
||||
return this.length;
|
||||
|
||||
@:noCompletion
|
||||
@:arrayAccess @:extern
|
||||
public inline function __get(idx:Int)
|
||||
{
|
||||
return ArrayBufferIO.getInt8(this.buffer, this.byteOffset + idx);
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
@:arrayAccess @:extern
|
||||
public inline function __set(idx:Int, val:Int)
|
||||
{
|
||||
ArrayBufferIO.setInt8(this.buffer, this.byteOffset + idx, val);
|
||||
return val;
|
||||
}
|
||||
|
||||
inline function toString()
|
||||
return this != null ? 'Int8Array [byteLength:${this.byteLength}, length:${this.length}]' : null;
|
||||
}
|
||||
#end // !js
|
||||
8
src/fixes/haxe/lime/utils/README.md
Normal file
8
src/fixes/haxe/lime/utils/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
environment:
|
||||
* lime 7.6.0
|
||||
* haxe 3.4.7
|
||||
* openfl build html5
|
||||
|
||||
code: ` to ArrayBufferView`
|
||||
|
||||
error: You can only declare from/to with compatible types
|
||||
161
src/fixes/haxe/lime/utils/UInt16Array.hx
Normal file
161
src/fixes/haxe/lime/utils/UInt16Array.hx
Normal file
@@ -0,0 +1,161 @@
|
||||
package lime.utils;
|
||||
|
||||
#if (js && !doc_gen)
|
||||
#if haxe4
|
||||
import js.lib.Uint8Array as JSUInt8Array;
|
||||
import js.lib.Uint16Array as JSUInt16Array;
|
||||
#else
|
||||
import js.html.Uint8Array as JSUInt8Array;
|
||||
import js.html.Uint16Array as JSUInt16Array;
|
||||
#end
|
||||
@:forward
|
||||
abstract UInt16Array(JSUInt16Array) from JSUInt16Array to JSUInt16Array/* to ArrayBufferView*/
|
||||
{
|
||||
public inline static var BYTES_PER_ELEMENT:Int = 2;
|
||||
|
||||
@:generic
|
||||
public inline function new<T>(?elements:Int, ?array:Array<T>, #if openfl ?vector:openfl.Vector<Int>, #end ?view:ArrayBufferView, ?buffer:ArrayBuffer,
|
||||
?byteoffset:Int = 0, ?len:Null<Int>)
|
||||
{
|
||||
if (elements != null)
|
||||
{
|
||||
this = new JSUInt16Array(elements);
|
||||
}
|
||||
else if (array != null)
|
||||
{
|
||||
this = new JSUInt16Array(untyped array);
|
||||
#if (openfl && commonjs)
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new JSUInt16Array(untyped (vector));
|
||||
#elseif openfl
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new JSUInt16Array(untyped untyped (vector).__array);
|
||||
#end
|
||||
}
|
||||
else if (view != null)
|
||||
{
|
||||
this = new JSUInt16Array(untyped view);
|
||||
}
|
||||
else if (buffer != null)
|
||||
{
|
||||
if (len == null)
|
||||
{
|
||||
this = new JSUInt16Array(buffer, byteoffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
this = new JSUInt16Array(buffer, byteoffset, len);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this = null;
|
||||
}
|
||||
}
|
||||
|
||||
@:arrayAccess @:extern inline function __set(idx:Int, val:UInt):UInt
|
||||
return this[idx] = val;
|
||||
|
||||
@:arrayAccess @:extern inline function __get(idx:Int):UInt
|
||||
return this[idx];
|
||||
|
||||
// non spec haxe conversions
|
||||
inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):UInt16Array
|
||||
{
|
||||
if (byteOffset == null) return new JSUInt16Array(cast bytes.getData());
|
||||
if (len == null) return new JSUInt16Array(cast bytes.getData(), byteOffset);
|
||||
return new JSUInt16Array(cast bytes.getData(), byteOffset, len);
|
||||
}
|
||||
|
||||
inline public function toBytes():haxe.io.Bytes
|
||||
{
|
||||
return @:privateAccess new haxe.io.Bytes(cast new JSUInt8Array(this.buffer));
|
||||
}
|
||||
|
||||
inline function toString()
|
||||
return this != null ? 'UInt16Array [byteLength:${this.byteLength}, length:${this.length}]' : null;
|
||||
}
|
||||
#else
|
||||
import lime.utils.ArrayBufferView;
|
||||
|
||||
@:forward
|
||||
abstract UInt16Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView
|
||||
{
|
||||
public inline static var BYTES_PER_ELEMENT:Int = 2;
|
||||
|
||||
public var length(get, never):Int;
|
||||
|
||||
@:generic
|
||||
public inline function new<T>(?elements:Int, ?buffer:ArrayBuffer, ?array:Array<T>, #if openfl ?vector:openfl.Vector<Int>, #end ?view:ArrayBufferView,
|
||||
?byteoffset:Int = 0, ?len:Null<Int>)
|
||||
{
|
||||
if (elements != null)
|
||||
{
|
||||
this = new ArrayBufferView(elements, Uint16);
|
||||
}
|
||||
else if (array != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Uint16).initArray(array);
|
||||
#if openfl
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Uint16).initArray(untyped (vector).__array);
|
||||
#end
|
||||
}
|
||||
else if (view != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Uint16).initTypedArray(view);
|
||||
}
|
||||
else if (buffer != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Uint16).initBuffer(buffer, byteoffset, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw "Invalid constructor arguments for UInt16Array";
|
||||
}
|
||||
}
|
||||
|
||||
// Public API
|
||||
public inline function subarray(begin:Int, end:Null<Int> = null):UInt16Array
|
||||
return this.subarray(begin, end);
|
||||
|
||||
// non spec haxe conversions
|
||||
inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):UInt16Array
|
||||
{
|
||||
return new UInt16Array(bytes, byteOffset, len);
|
||||
}
|
||||
|
||||
inline public function toBytes():haxe.io.Bytes
|
||||
{
|
||||
return this.buffer;
|
||||
}
|
||||
|
||||
// Internal
|
||||
inline function get_length()
|
||||
return this.length;
|
||||
|
||||
@:noCompletion
|
||||
@:arrayAccess @:extern
|
||||
public inline function __get(idx:Int)
|
||||
{
|
||||
return ArrayBufferIO.getUint16(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT));
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
@:arrayAccess @:extern
|
||||
public inline function __set(idx:Int, val:UInt)
|
||||
{
|
||||
ArrayBufferIO.setUint16(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT), val);
|
||||
return val;
|
||||
}
|
||||
|
||||
inline function toString()
|
||||
return this != null ? 'UInt16Array [byteLength:${this.byteLength}, length:${this.length}]' : null;
|
||||
}
|
||||
#end // !js
|
||||
161
src/fixes/haxe/lime/utils/UInt32Array.hx
Normal file
161
src/fixes/haxe/lime/utils/UInt32Array.hx
Normal file
@@ -0,0 +1,161 @@
|
||||
package lime.utils;
|
||||
|
||||
#if (js && !doc_gen)
|
||||
#if haxe4
|
||||
import js.lib.Uint8Array as JSUInt8Array;
|
||||
import js.lib.Uint32Array as JSUInt32Array;
|
||||
#else
|
||||
import js.html.Uint8Array as JSUInt8Array;
|
||||
import js.html.Uint32Array as JSUInt32Array;
|
||||
#end
|
||||
@:forward
|
||||
abstract UInt32Array(JSUInt32Array) from JSUInt32Array to JSUInt32Array/* to ArrayBufferView*/
|
||||
{
|
||||
public inline static var BYTES_PER_ELEMENT:Int = 4;
|
||||
|
||||
@:generic
|
||||
public inline function new<T>(?elements:Int, ?array:Array<T>, #if openfl ?vector:openfl.Vector<Int>, #end ?view:ArrayBufferView, ?buffer:ArrayBuffer,
|
||||
?byteoffset:Int = 0, ?len:Null<Int>)
|
||||
{
|
||||
if (elements != null)
|
||||
{
|
||||
this = new JSUInt32Array(elements);
|
||||
}
|
||||
else if (array != null)
|
||||
{
|
||||
this = new JSUInt32Array(untyped array);
|
||||
#if (openfl && commonjs)
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new JSUInt32Array(untyped (vector));
|
||||
#elseif openfl
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new JSUInt32Array(untyped untyped (vector).__array);
|
||||
#end
|
||||
}
|
||||
else if (view != null)
|
||||
{
|
||||
this = new JSUInt32Array(untyped view);
|
||||
}
|
||||
else if (buffer != null)
|
||||
{
|
||||
if (len == null)
|
||||
{
|
||||
this = new JSUInt32Array(buffer, byteoffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
this = new JSUInt32Array(buffer, byteoffset, len);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this = null;
|
||||
}
|
||||
}
|
||||
|
||||
@:arrayAccess @:extern inline function __set(idx:Int, val:UInt):UInt
|
||||
return this[idx] = val;
|
||||
|
||||
@:arrayAccess @:extern inline function __get(idx:Int):UInt
|
||||
return this[idx];
|
||||
|
||||
// non spec haxe conversions
|
||||
inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):UInt32Array
|
||||
{
|
||||
if (byteOffset == null) return new JSUInt32Array(cast bytes.getData());
|
||||
if (len == null) return new JSUInt32Array(cast bytes.getData(), byteOffset);
|
||||
return new JSUInt32Array(cast bytes.getData(), byteOffset, len);
|
||||
}
|
||||
|
||||
inline public function toBytes():haxe.io.Bytes
|
||||
{
|
||||
return @:privateAccess new haxe.io.Bytes(cast new JSUInt8Array(this.buffer));
|
||||
}
|
||||
|
||||
inline function toString()
|
||||
return this != null ? 'UInt32Array [byteLength:${this.byteLength}, length:${this.length}]' : null;
|
||||
}
|
||||
#else
|
||||
import lime.utils.ArrayBufferView;
|
||||
|
||||
@:forward
|
||||
abstract UInt32Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView
|
||||
{
|
||||
public inline static var BYTES_PER_ELEMENT:Int = 4;
|
||||
|
||||
public var length(get, never):Int;
|
||||
|
||||
@:generic
|
||||
public inline function new<T>(?elements:Int, ?buffer:ArrayBuffer, ?array:Array<T>, #if openfl ?vector:openfl.Vector<Int>, #end ?view:ArrayBufferView,
|
||||
?byteoffset:Int = 0, ?len:Null<Int>)
|
||||
{
|
||||
if (elements != null)
|
||||
{
|
||||
this = new ArrayBufferView(elements, Uint32);
|
||||
}
|
||||
else if (array != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Uint32).initArray(array);
|
||||
#if openfl
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Uint32).initArray(untyped (vector).__array);
|
||||
#end
|
||||
}
|
||||
else if (view != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Uint32).initTypedArray(view);
|
||||
}
|
||||
else if (buffer != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Uint32).initBuffer(buffer, byteoffset, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw "Invalid constructor arguments for UInt32Array";
|
||||
}
|
||||
}
|
||||
|
||||
// Public API
|
||||
public inline function subarray(begin:Int, end:Null<Int> = null):UInt32Array
|
||||
return this.subarray(begin, end);
|
||||
|
||||
// non spec haxe conversions
|
||||
inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):UInt32Array
|
||||
{
|
||||
return new UInt32Array(bytes, byteOffset, len);
|
||||
}
|
||||
|
||||
inline public function toBytes():haxe.io.Bytes
|
||||
{
|
||||
return this.buffer;
|
||||
}
|
||||
|
||||
// Internal
|
||||
inline function get_length()
|
||||
return this.length;
|
||||
|
||||
@:noCompletion
|
||||
@:arrayAccess @:extern
|
||||
public inline function __get(idx:Int)
|
||||
{
|
||||
return ArrayBufferIO.getUint32(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT));
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
@:arrayAccess @:extern
|
||||
public inline function __set(idx:Int, val:UInt)
|
||||
{
|
||||
ArrayBufferIO.setUint32(this.buffer, this.byteOffset + (idx * BYTES_PER_ELEMENT), val);
|
||||
return val;
|
||||
}
|
||||
|
||||
inline function toString()
|
||||
return this != null ? 'UInt32Array [byteLength:${this.byteLength}, length:${this.length}]' : null;
|
||||
}
|
||||
#end // !js
|
||||
159
src/fixes/haxe/lime/utils/UInt8Array.hx
Normal file
159
src/fixes/haxe/lime/utils/UInt8Array.hx
Normal file
@@ -0,0 +1,159 @@
|
||||
package lime.utils;
|
||||
|
||||
#if (js && !doc_gen)
|
||||
#if haxe4
|
||||
import js.lib.Uint8Array as JSUInt8Array;
|
||||
#else
|
||||
import js.html.Uint8Array as JSUInt8Array;
|
||||
#end
|
||||
@:forward
|
||||
abstract UInt8Array(JSUInt8Array) from JSUInt8Array to JSUInt8Array/* to ArrayBufferView*/
|
||||
{
|
||||
public inline static var BYTES_PER_ELEMENT:Int = 1;
|
||||
|
||||
@:generic
|
||||
public inline function new<T>(?elements:Int, ?array:Array<T>, #if openfl ?vector:openfl.Vector<Int>, #end ?view:ArrayBufferView, ?buffer:ArrayBuffer,
|
||||
?byteoffset:Int = 0, ?len:Null<Int>)
|
||||
{
|
||||
if (elements != null)
|
||||
{
|
||||
this = new JSUInt8Array(elements);
|
||||
}
|
||||
else if (array != null)
|
||||
{
|
||||
this = new JSUInt8Array(untyped array);
|
||||
#if (openfl && commonjs)
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new JSUInt8Array(untyped (vector));
|
||||
#elseif openfl
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new JSUInt8Array(untyped untyped (vector).__array);
|
||||
#end
|
||||
}
|
||||
else if (view != null)
|
||||
{
|
||||
this = new JSUInt8Array(untyped view);
|
||||
}
|
||||
else if (buffer != null)
|
||||
{
|
||||
if (len == null)
|
||||
{
|
||||
this = new JSUInt8Array(buffer, byteoffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
this = new JSUInt8Array(buffer, byteoffset, len);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this = null;
|
||||
}
|
||||
}
|
||||
|
||||
@:arrayAccess @:extern inline function __set(idx:Int, val:UInt):UInt
|
||||
return this[idx] = val;
|
||||
|
||||
@:arrayAccess @:extern inline function __get(idx:Int):UInt
|
||||
return this[idx];
|
||||
|
||||
// non spec haxe conversions
|
||||
inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int, ?len:Int):UInt8Array
|
||||
{
|
||||
if (byteOffset == null) return new JSUInt8Array(cast bytes.getData());
|
||||
if (len == null) return new JSUInt8Array(cast bytes.getData(), byteOffset);
|
||||
return new JSUInt8Array(cast bytes.getData(), byteOffset, len);
|
||||
}
|
||||
|
||||
inline public function toBytes():haxe.io.Bytes
|
||||
{
|
||||
return @:privateAccess new haxe.io.Bytes(cast new JSUInt8Array(this.buffer));
|
||||
}
|
||||
|
||||
inline function toString()
|
||||
return this != null ? 'UInt8Array [byteLength:${this.byteLength}, length:${this.length}]' : null;
|
||||
}
|
||||
#else
|
||||
import lime.utils.ArrayBufferView;
|
||||
|
||||
@:forward
|
||||
abstract UInt8Array(ArrayBufferView) from ArrayBufferView to ArrayBufferView
|
||||
{
|
||||
public inline static var BYTES_PER_ELEMENT:Int = 1;
|
||||
|
||||
public var length(get, never):Int;
|
||||
|
||||
@:generic
|
||||
public inline function new<T>(?elements:Int, ?buffer:ArrayBuffer, ?array:Array<T>, #if openfl ?vector:openfl.Vector<Int>, #end ?view:ArrayBufferView,
|
||||
?byteoffset:Int = 0, ?len:Null<Int>)
|
||||
{
|
||||
if (elements != null)
|
||||
{
|
||||
this = new ArrayBufferView(elements, Uint8);
|
||||
}
|
||||
else if (array != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Uint8).initArray(array);
|
||||
#if openfl
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Uint8).initArray(untyped (vector).__array);
|
||||
#end
|
||||
}
|
||||
else if (view != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Uint8).initTypedArray(view);
|
||||
}
|
||||
else if (buffer != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Uint8).initBuffer(buffer, byteoffset, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw "Invalid constructor arguments for UInt8Array";
|
||||
}
|
||||
}
|
||||
|
||||
// Public API
|
||||
public inline function subarray(begin:Int, end:Null<Int> = null):UInt8Array
|
||||
return this.subarray(begin, end);
|
||||
|
||||
// non spec haxe conversions
|
||||
inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):UInt8Array
|
||||
{
|
||||
return new UInt8Array(bytes, byteOffset, len);
|
||||
}
|
||||
|
||||
inline public function toBytes():haxe.io.Bytes
|
||||
{
|
||||
return this.buffer;
|
||||
}
|
||||
|
||||
// Internal
|
||||
inline function toString()
|
||||
return this != null ? 'UInt8Array [byteLength:${this.byteLength}, length:${this.length}]' : null;
|
||||
|
||||
inline function get_length()
|
||||
return this.length;
|
||||
|
||||
@:noCompletion
|
||||
@:arrayAccess @:extern
|
||||
public inline function __get(idx:Int)
|
||||
{
|
||||
return ArrayBufferIO.getUint8(this.buffer, this.byteOffset + idx);
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
@:arrayAccess @:extern
|
||||
public inline function __set(idx:Int, val:UInt)
|
||||
{
|
||||
ArrayBufferIO.setUint8(this.buffer, this.byteOffset + idx, val);
|
||||
return val;
|
||||
}
|
||||
}
|
||||
#end // !js
|
||||
171
src/fixes/haxe/lime/utils/UInt8ClampedArray.hx
Normal file
171
src/fixes/haxe/lime/utils/UInt8ClampedArray.hx
Normal file
@@ -0,0 +1,171 @@
|
||||
package lime.utils;
|
||||
|
||||
#if (js && !doc_gen)
|
||||
#if haxe4
|
||||
import js.lib.Uint8Array as JSUInt8Array;
|
||||
import js.lib.Uint8ClampedArray as JSUInt8ClampedArray;
|
||||
#else
|
||||
import js.html.Uint8Array as JSUInt8Array;
|
||||
import js.html.Uint8ClampedArray as JSUInt8ClampedArray;
|
||||
#end
|
||||
@:forward
|
||||
abstract UInt8ClampedArray(JSUInt8ClampedArray) from JSUInt8ClampedArray to JSUInt8ClampedArray/* to ArrayBufferView*/
|
||||
{
|
||||
public inline static var BYTES_PER_ELEMENT:Int = 1;
|
||||
|
||||
@:generic
|
||||
public inline function new<T>(?elements:Int, ?array:Array<T>, #if openfl ?vector:openfl.Vector<Int>, #end ?view:ArrayBufferView, ?buffer:ArrayBuffer,
|
||||
?byteoffset:Int = 0, ?len:Null<Int>)
|
||||
{
|
||||
if (elements != null)
|
||||
{
|
||||
this = new JSUInt8ClampedArray(elements);
|
||||
}
|
||||
else if (array != null)
|
||||
{
|
||||
this = new JSUInt8ClampedArray(untyped array);
|
||||
#if (openfl && commonjs)
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new JSUInt8ClampedArray(untyped (vector));
|
||||
#elseif openfl
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new JSUInt8ClampedArray(untyped untyped (vector).__array);
|
||||
#end
|
||||
}
|
||||
else if (view != null)
|
||||
{
|
||||
this = new JSUInt8ClampedArray(untyped view);
|
||||
}
|
||||
else if (buffer != null)
|
||||
{
|
||||
if (len == null)
|
||||
{
|
||||
this = new JSUInt8ClampedArray(buffer, byteoffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
this = new JSUInt8ClampedArray(buffer, byteoffset, len);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this = null;
|
||||
}
|
||||
}
|
||||
|
||||
@:arrayAccess @:extern inline function __set(idx:Int, val:UInt):UInt
|
||||
return this[idx] = _clamp(val);
|
||||
|
||||
@:arrayAccess @:extern inline function __get(idx:Int):UInt
|
||||
return this[idx];
|
||||
|
||||
// non spec haxe conversions
|
||||
inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):UInt8ClampedArray
|
||||
{
|
||||
if (byteOffset == null) return new JSUInt8ClampedArray(cast bytes.getData());
|
||||
if (len == null) return new JSUInt8ClampedArray(cast bytes.getData(), byteOffset);
|
||||
return new JSUInt8ClampedArray(cast bytes.getData(), byteOffset, len);
|
||||
}
|
||||
|
||||
inline public function toBytes():haxe.io.Bytes
|
||||
{
|
||||
return @:privateAccess new haxe.io.Bytes(cast new JSUInt8Array(this.buffer));
|
||||
}
|
||||
|
||||
inline function toString()
|
||||
return this != null ? 'UInt8ClampedArray [byteLength:${this.byteLength}, length:${this.length}]' : null;
|
||||
|
||||
// internal
|
||||
// clamp a Int to a 0-255 Uint8
|
||||
static function _clamp(_in:Float):Int
|
||||
{
|
||||
var _out = Std.int(_in);
|
||||
_out = _out > 255 ? 255 : _out;
|
||||
return _out < 0 ? 0 : _out;
|
||||
} // _clamp
|
||||
}
|
||||
#else
|
||||
import lime.utils.ArrayBufferView;
|
||||
|
||||
@:forward
|
||||
@:arrayAccess
|
||||
abstract UInt8ClampedArray(ArrayBufferView) from ArrayBufferView to ArrayBufferView
|
||||
{
|
||||
public inline static var BYTES_PER_ELEMENT:Int = 1;
|
||||
|
||||
public var length(get, never):Int;
|
||||
|
||||
@:generic
|
||||
public inline function new<T>(?elements:Int, ?buffer:ArrayBuffer, ?array:Array<T>, #if openfl ?vector:openfl.Vector<Int>, #end ?view:ArrayBufferView,
|
||||
?byteoffset:Int = 0, ?len:Null<Int>)
|
||||
{
|
||||
if (elements != null)
|
||||
{
|
||||
this = new ArrayBufferView(elements, Uint8Clamped);
|
||||
}
|
||||
else if (array != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Uint8Clamped).initArray(array);
|
||||
#if openfl
|
||||
}
|
||||
else if (vector != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Uint8Clamped).initArray(untyped (vector).__array);
|
||||
#end
|
||||
}
|
||||
else if (view != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Uint8Clamped).initTypedArray(view);
|
||||
}
|
||||
else if (buffer != null)
|
||||
{
|
||||
this = new ArrayBufferView(0, Uint8Clamped).initBuffer(buffer, byteoffset, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw "Invalid constructor arguments for UInt8ClampedArray";
|
||||
}
|
||||
}
|
||||
|
||||
// Public API
|
||||
public inline function subarray(begin:Int, end:Null<Int> = null):UInt8ClampedArray
|
||||
return this.subarray(begin, end);
|
||||
|
||||
// non spec haxe conversions
|
||||
inline public static function fromBytes(bytes:haxe.io.Bytes, ?byteOffset:Int = 0, ?len:Int):UInt8ClampedArray
|
||||
{
|
||||
return new UInt8ClampedArray(bytes, byteOffset, len);
|
||||
}
|
||||
|
||||
inline public function toBytes():haxe.io.Bytes
|
||||
{
|
||||
return this.buffer;
|
||||
}
|
||||
|
||||
// Internal
|
||||
inline function get_length()
|
||||
return this.length;
|
||||
|
||||
@:noCompletion
|
||||
@:arrayAccess @:extern
|
||||
public inline function __get(idx:Int)
|
||||
{
|
||||
return ArrayBufferIO.getUint8(this.buffer, this.byteOffset + idx);
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
@:arrayAccess @:extern
|
||||
public inline function __set(idx:Int, val:UInt)
|
||||
{
|
||||
ArrayBufferIO.setUint8Clamped(this.buffer, this.byteOffset + idx, val);
|
||||
return val;
|
||||
}
|
||||
|
||||
inline function toString()
|
||||
return this != null ? 'UInt8ClampedArray [byteLength:${this.byteLength}, length:${this.length}]' : null;
|
||||
}
|
||||
#end // !js
|
||||
Reference in New Issue
Block a user