forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
196
Kha/Tools/macos/std/hl/_std/Date.hx
Normal file
196
Kha/Tools/macos/std/hl/_std/Date.hx
Normal file
@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import hl.Ref;
|
||||
|
||||
@:coreApi final class Date {
|
||||
private var t:Int;
|
||||
|
||||
public function new(year:Int, month:Int, day:Int, hour:Int, min:Int, sec:Int):Void {
|
||||
t = date_new(year, month, day, hour, min, sec);
|
||||
}
|
||||
|
||||
public function getTime():Float {
|
||||
return date_get_time(t);
|
||||
}
|
||||
|
||||
public function getFullYear():Int {
|
||||
var v = 0;
|
||||
date_get_inf(t, v, null, null, null, null, null, null);
|
||||
return v;
|
||||
}
|
||||
|
||||
public function getMonth():Int {
|
||||
var v = 0;
|
||||
date_get_inf(t, null, v, null, null, null, null, null);
|
||||
return v;
|
||||
}
|
||||
|
||||
public function getDate():Int {
|
||||
var v = 0;
|
||||
date_get_inf(t, null, null, v, null, null, null, null);
|
||||
return v;
|
||||
}
|
||||
|
||||
public function getHours():Int {
|
||||
var v = 0;
|
||||
date_get_inf(t, null, null, null, v, null, null, null);
|
||||
return v;
|
||||
}
|
||||
|
||||
public function getMinutes():Int {
|
||||
var v = 0;
|
||||
date_get_inf(t, null, null, null, null, v, null, null);
|
||||
return v;
|
||||
}
|
||||
|
||||
public function getSeconds():Int {
|
||||
var v = 0;
|
||||
date_get_inf(t, null, null, null, null, null, v, null);
|
||||
return v;
|
||||
}
|
||||
|
||||
public function getDay():Int {
|
||||
var v = 0;
|
||||
date_get_inf(t, null, null, null, null, null, null, v);
|
||||
return v;
|
||||
}
|
||||
|
||||
public function getUTCFullYear():Int {
|
||||
var v = 0;
|
||||
date_get_utc_inf(t, v, null, null, null, null, null, null);
|
||||
return v;
|
||||
}
|
||||
|
||||
public function getUTCMonth():Int {
|
||||
var v = 0;
|
||||
date_get_utc_inf(t, null, v, null, null, null, null, null);
|
||||
return v;
|
||||
}
|
||||
|
||||
public function getUTCDate():Int {
|
||||
var v = 0;
|
||||
date_get_utc_inf(t, null, null, v, null, null, null, null);
|
||||
return v;
|
||||
}
|
||||
|
||||
public function getUTCHours():Int {
|
||||
var v = 0;
|
||||
date_get_utc_inf(t, null, null, null, v, null, null, null);
|
||||
return v;
|
||||
}
|
||||
|
||||
public function getUTCMinutes():Int {
|
||||
var v = 0;
|
||||
date_get_utc_inf(t, null, null, null, null, v, null, null);
|
||||
return v;
|
||||
}
|
||||
|
||||
public function getUTCSeconds():Int {
|
||||
var v = 0;
|
||||
date_get_utc_inf(t, null, null, null, null, null, v, null);
|
||||
return v;
|
||||
}
|
||||
|
||||
public function getUTCDay():Int {
|
||||
var v = 0;
|
||||
date_get_utc_inf(t, null, null, null, null, null, null, v);
|
||||
return v;
|
||||
}
|
||||
|
||||
public function getTimezoneOffset():Int {
|
||||
var y = 0;
|
||||
var mo = 0;
|
||||
var d = 0;
|
||||
var h = 0;
|
||||
var m = 0;
|
||||
var s = 0;
|
||||
date_get_utc_inf(t, y, mo, d, h, m, s, null);
|
||||
return Std.int((date_new(y, mo, d, h, m, s) - t) / 60);
|
||||
}
|
||||
|
||||
@:keep public function toString():String {
|
||||
var outLen = 0;
|
||||
var bytes = date_to_string(t, outLen);
|
||||
return @:privateAccess String.__alloc__(bytes, outLen);
|
||||
}
|
||||
|
||||
public static function now():Date {
|
||||
var d:Date = untyped $new(Date);
|
||||
d.t = date_now();
|
||||
return d;
|
||||
}
|
||||
|
||||
static function fromInt(t:Int):Date {
|
||||
var d:Date = untyped $new(Date);
|
||||
d.t = t;
|
||||
return d;
|
||||
}
|
||||
|
||||
public static function fromTime(t:Float):Date {
|
||||
var d:Date = untyped $new(Date);
|
||||
d.t = date_from_time(t);
|
||||
return d;
|
||||
}
|
||||
|
||||
public static function fromString(s:String):Date {
|
||||
var d:Date = untyped $new(Date);
|
||||
d.t = date_from_string(@:privateAccess s.bytes, s.length << 1);
|
||||
return d;
|
||||
}
|
||||
|
||||
@:hlNative
|
||||
static function date_new(year:Int, month:Int, day:Int, hours:Int, minutes:Int, seconds:Int):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative
|
||||
static function date_now():Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative
|
||||
static function date_from_time(t:Float):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative
|
||||
static function date_from_string(b:hl.Bytes, len:Int):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative
|
||||
static function date_get_time(t:Int):Float {
|
||||
return 0.;
|
||||
}
|
||||
|
||||
@:hlNative
|
||||
static function date_get_inf(t:Int, year:Ref<Int>, month:Ref<Int>, day:Ref<Int>, hours:Ref<Int>, minutes:Ref<Int>, seconds:Ref<Int>, wday:Ref<Int>):Void {}
|
||||
|
||||
@:hlNative(1.11)
|
||||
static function date_get_utc_inf(t:Int, year:Ref<Int>, month:Ref<Int>, day:Ref<Int>, hours:Ref<Int>, minutes:Ref<Int>, seconds:Ref<Int>, wday:Ref<Int>):Void {}
|
||||
|
||||
@:hlNative
|
||||
static function date_to_string(t:Int, outLen:Ref<Int>):hl.Bytes {
|
||||
return null;
|
||||
}
|
||||
}
|
202
Kha/Tools/macos/std/hl/_std/EReg.hx
Normal file
202
Kha/Tools/macos/std/hl/_std/EReg.hx
Normal file
@ -0,0 +1,202 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
private typedef ERegValue = hl.Abstract<"ereg">;
|
||||
|
||||
@:access(String)
|
||||
@:coreApi final class EReg {
|
||||
var r:ERegValue;
|
||||
var last:String;
|
||||
var global:Bool;
|
||||
|
||||
public function new(r:String, opt:String):Void {
|
||||
var a = opt.split("g");
|
||||
global = a.length > 1;
|
||||
if (global)
|
||||
opt = a.join("");
|
||||
this.r = regexp_new_options(r.bytes, opt.bytes);
|
||||
}
|
||||
|
||||
public function match(s:String):Bool {
|
||||
var p = regexp_match(r, s.bytes, 0, s.length);
|
||||
if (p)
|
||||
last = s;
|
||||
else
|
||||
last = null;
|
||||
return p;
|
||||
}
|
||||
|
||||
public function matched(n:Int):String {
|
||||
var len = 0;
|
||||
var m = regexp_matched_pos(r, n, len);
|
||||
return m < 0 ? null : last.substr(m, len);
|
||||
}
|
||||
|
||||
public function matchedLeft():String {
|
||||
var p = regexp_matched_pos(r, 0, null);
|
||||
return last.substr(0, p);
|
||||
}
|
||||
|
||||
public function matchedRight():String {
|
||||
var len = 0;
|
||||
var p = regexp_matched_pos(r, 0, len);
|
||||
return last.substr(p + len);
|
||||
}
|
||||
|
||||
public function matchedPos():{pos:Int, len:Int} {
|
||||
var len = 0;
|
||||
var p = regexp_matched_pos(r, 0, len);
|
||||
if (p < 0)
|
||||
return null;
|
||||
return {pos: p, len: len};
|
||||
}
|
||||
|
||||
public function matchSub(s:String, pos:Int, len:Int = -1):Bool {
|
||||
var p = regexp_match(r, s.bytes, pos, len < 0 ? s.length - pos : len);
|
||||
if (p)
|
||||
last = s;
|
||||
else
|
||||
last = null;
|
||||
return p;
|
||||
}
|
||||
|
||||
public function split(s:String):Array<String> {
|
||||
var pos = 0;
|
||||
var len = s.length;
|
||||
var a = new Array();
|
||||
var first = true;
|
||||
do {
|
||||
if (!regexp_match(r, s.bytes, pos, len))
|
||||
break;
|
||||
var plen = 0;
|
||||
var p = regexp_matched_pos(r, 0, plen);
|
||||
if (plen == 0 && !first) {
|
||||
if (p == s.length)
|
||||
break;
|
||||
p++;
|
||||
}
|
||||
a.push(s.substr(pos, p - pos));
|
||||
var tot = p + plen - pos;
|
||||
pos += tot;
|
||||
len -= tot;
|
||||
first = false;
|
||||
} while (global);
|
||||
a.push(s.substr(pos, len));
|
||||
return a;
|
||||
}
|
||||
|
||||
public function replace(s:String, by:String):String {
|
||||
var b = new StringBuf();
|
||||
var pos = 0;
|
||||
var len = s.length;
|
||||
var a = by.split("$");
|
||||
var first = true;
|
||||
do {
|
||||
if (!regexp_match(r, s.bytes, pos, len))
|
||||
break;
|
||||
var plen = 0;
|
||||
var p = regexp_matched_pos(r, 0, plen);
|
||||
if (plen == 0 && !first) {
|
||||
if (p == s.length)
|
||||
break;
|
||||
p++;
|
||||
}
|
||||
b.addSub(s, pos, p - pos);
|
||||
if (a.length > 0)
|
||||
b.add(a[0]);
|
||||
var i = 1;
|
||||
while (i < a.length) {
|
||||
var k = a[i];
|
||||
var c = StringTools.fastCodeAt(k, 0);
|
||||
// 1...9
|
||||
if (c >= 49 && c <= 57) {
|
||||
var plen = 0;
|
||||
var p = try regexp_matched_pos(r, Std.int(c) - 48, plen) catch (e:String) -1;
|
||||
if (p < 0) {
|
||||
b.add("$");
|
||||
b.add(k);
|
||||
} else {
|
||||
if (p >= 0)
|
||||
b.addSub(s, p, plen);
|
||||
b.addSub(k, 1, k.length - 1);
|
||||
}
|
||||
} else if (c == 0) {
|
||||
b.add("$");
|
||||
i++;
|
||||
var k2 = a[i];
|
||||
if (k2 != null && k2.length > 0)
|
||||
b.add(k2);
|
||||
} else
|
||||
b.add("$" + k);
|
||||
i++;
|
||||
}
|
||||
var tot = p + plen - pos;
|
||||
pos += tot;
|
||||
len -= tot;
|
||||
first = false;
|
||||
} while (global);
|
||||
b.addSub(s, pos, len);
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
public function map(s:String, f:EReg->String):String {
|
||||
var offset = 0;
|
||||
var buf = new StringBuf();
|
||||
do {
|
||||
if (offset >= s.length)
|
||||
break;
|
||||
else if (!matchSub(s, offset)) {
|
||||
buf.add(s.substr(offset));
|
||||
break;
|
||||
}
|
||||
var plen = 0;
|
||||
var p = regexp_matched_pos(r, 0, plen);
|
||||
buf.add(s.substr(offset, p - offset));
|
||||
buf.add(f(this));
|
||||
if (plen == 0) {
|
||||
buf.add(s.substr(p, 1));
|
||||
offset = p + 1;
|
||||
} else
|
||||
offset = p + plen;
|
||||
} while (global);
|
||||
if (!global && offset > 0 && offset < s.length)
|
||||
buf.add(s.substr(offset));
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static function escape(s:String):String {
|
||||
return escapeRegExpRe.map(s, function(r) return "\\" + r.matched(0));
|
||||
}
|
||||
|
||||
static var escapeRegExpRe = ~/[\[\]{}()*+?.\\\^$|]/g;
|
||||
|
||||
@:hlNative("std", "regexp_new_options") static function regexp_new_options(bytes:hl.Bytes, options:hl.Bytes):ERegValue {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "regexp_match") static function regexp_match(r:ERegValue, str:hl.Bytes, pos:Int, size:Int):Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
@:hlNative("std", "regexp_matched_pos") static function regexp_matched_pos(r:ERegValue, n:Int, size:hl.Ref<Int>):Int {
|
||||
return 0;
|
||||
}
|
||||
}
|
104
Kha/Tools/macos/std/hl/_std/Math.hx
Normal file
104
Kha/Tools/macos/std/hl/_std/Math.hx
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
@:coreApi
|
||||
class Math {
|
||||
@:hlNative("std", "math_sqrt") public static function sqrt(v:Float):Float
|
||||
return 0.;
|
||||
|
||||
@:hlNative("std", "math_abs") public static function abs(v:Float):Float
|
||||
return 0.;
|
||||
|
||||
@:hlNative("std", "math_floor") public static function floor(v:Float):Int
|
||||
return 0;
|
||||
|
||||
@:hlNative("std", "math_round") public static function round(v:Float):Int
|
||||
return 0;
|
||||
|
||||
@:hlNative("std", "math_ceil") public static function ceil(v:Float):Int
|
||||
return 0;
|
||||
|
||||
@:hlNative("std", "math_isfinite") public static function isFinite(f:Float):Bool
|
||||
return true;
|
||||
|
||||
@:hlNative("std", "math_isnan") public static function isNaN(f:Float):Bool
|
||||
return false;
|
||||
|
||||
@:hlNative("std", "math_ffloor") public static function ffloor(v:Float):Float
|
||||
return 0.;
|
||||
|
||||
@:hlNative("std", "math_fround") public static function fround(v:Float):Float
|
||||
return 0.;
|
||||
|
||||
@:hlNative("std", "math_fceil") public static function fceil(v:Float):Float
|
||||
return 0.;
|
||||
|
||||
@:hlNative("std", "math_cos") public static function cos(v:Float):Float
|
||||
return 0.;
|
||||
|
||||
@:hlNative("std", "math_sin") public static function sin(v:Float):Float
|
||||
return 0.;
|
||||
|
||||
@:hlNative("std", "math_exp") public static function exp(v:Float):Float
|
||||
return 0.;
|
||||
|
||||
@:hlNative("std", "math_log") public static function log(v:Float):Float
|
||||
return 0.;
|
||||
|
||||
@:hlNative("std", "math_tan") public static function tan(v:Float):Float
|
||||
return 0.;
|
||||
|
||||
@:hlNative("std", "math_atan") public static function atan(v:Float):Float
|
||||
return 0.;
|
||||
|
||||
@:hlNative("std", "math_acos") public static function acos(v:Float):Float
|
||||
return 0.;
|
||||
|
||||
@:hlNative("std", "math_asin") public static function asin(v:Float):Float
|
||||
return 0.;
|
||||
|
||||
@:hlNative("std", "math_pow") public static function pow(v:Float, exp:Float):Float
|
||||
return 0.;
|
||||
|
||||
@:hlNative("std", "math_atan2") public static function atan2(y:Float, x:Float):Float
|
||||
return 0.;
|
||||
|
||||
public static function random():Float
|
||||
return @:privateAccess Std.rnd_float(Std.rnd);
|
||||
|
||||
public static function min(a:Float, b:Float):Float
|
||||
return a < b || isNaN(a) ? a : b;
|
||||
|
||||
public static function max(a:Float, b:Float):Float
|
||||
return a < b || isNaN(b) ? b : a;
|
||||
|
||||
public static var PI(default, null):Float;
|
||||
public static var NaN(default, null):Float;
|
||||
public static var POSITIVE_INFINITY(default, null):Float;
|
||||
public static var NEGATIVE_INFINITY(default, null):Float;
|
||||
|
||||
static function __init__():Void {
|
||||
PI = 3.1415926535897932384626433832795;
|
||||
NaN = 0. / 0.;
|
||||
POSITIVE_INFINITY = 1. / 0.;
|
||||
NEGATIVE_INFINITY = -1. / 0.;
|
||||
}
|
||||
}
|
142
Kha/Tools/macos/std/hl/_std/Reflect.hx
Normal file
142
Kha/Tools/macos/std/hl/_std/Reflect.hx
Normal file
@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
@:coreApi
|
||||
class Reflect {
|
||||
public static function hasField(o:Dynamic, field:String):Bool {
|
||||
if (field == null)
|
||||
return false;
|
||||
var hash = @:privateAccess field.bytes.hash();
|
||||
return hl.Api.hasField(o, hash);
|
||||
}
|
||||
|
||||
public static function field(o:Dynamic, field:String):Dynamic {
|
||||
if (field == null)
|
||||
return null;
|
||||
var hash = @:privateAccess field.bytes.hash();
|
||||
return hl.Api.getField(o, hash);
|
||||
}
|
||||
|
||||
public static function setField(o:Dynamic, field:String, value:Dynamic):Void {
|
||||
var hash = @:privateAccess field.bytes.hash();
|
||||
hl.Api.setField(o, hash, value);
|
||||
}
|
||||
|
||||
public static function getProperty(o:Dynamic, field:String):Dynamic {
|
||||
var f:Dynamic = Reflect.field(o, "get_" + field);
|
||||
if (f != null)
|
||||
return f();
|
||||
return Reflect.field(o, field);
|
||||
}
|
||||
|
||||
public static function setProperty(o:Dynamic, field:String, value:Dynamic):Void {
|
||||
var f:Dynamic = Reflect.field(o, "set_" + field);
|
||||
if (f != null)
|
||||
f(value);
|
||||
else
|
||||
setField(o, field, value);
|
||||
}
|
||||
|
||||
public static function callMethod(o:Dynamic, func:haxe.Constraints.Function, args:Array<Dynamic>):Dynamic {
|
||||
var args:hl.types.ArrayDyn = cast args;
|
||||
|
||||
var ft = hl.Type.getDynamic(func);
|
||||
if (ft.kind != HFun)
|
||||
throw "Invalid function " + func;
|
||||
|
||||
var count = args.length;
|
||||
var need = ft.getArgsCount();
|
||||
var nargs = count < need ? need : count;
|
||||
var cval:Dynamic = hl.Api.getClosureValue(func);
|
||||
if (cval != null) {
|
||||
func = hl.Api.noClosure(func);
|
||||
nargs++;
|
||||
}
|
||||
|
||||
var a = new hl.NativeArray<Dynamic>(nargs);
|
||||
if (cval == null) {
|
||||
for (i in 0...count)
|
||||
a[i] = args.getDyn(i);
|
||||
} else {
|
||||
a[0] = cval;
|
||||
for (i in 0...count)
|
||||
a[i + 1] = args.getDyn(i);
|
||||
}
|
||||
return hl.Api.callMethod(func, a);
|
||||
}
|
||||
|
||||
@:hlNative("std", "obj_fields") static function getObjectFields(v:Dynamic):hl.NativeArray<hl.Bytes> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function fields(o:Dynamic):Array<String> {
|
||||
var fields = getObjectFields(o);
|
||||
if (fields == null)
|
||||
return [];
|
||||
return [for (f in fields) @:privateAccess String.fromUCS2(f)];
|
||||
}
|
||||
|
||||
public static inline function isFunction(f:Dynamic):Bool {
|
||||
return hl.Type.getDynamic(f).kind == HFun;
|
||||
}
|
||||
|
||||
@:hlNative("std", "dyn_compare")
|
||||
public static function compare<T>(a:T, b:T):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative("std", "fun_compare")
|
||||
public static function compareMethods(f1:Dynamic, f2:Dynamic):Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function isObject(v:Dynamic):Bool {
|
||||
var t = hl.Type.getDynamic(v);
|
||||
return switch (t.kind) {
|
||||
case HObj, HDynObj, HVirtual: true;
|
||||
default: false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function isEnumValue(v:Dynamic):Bool {
|
||||
var t = hl.Type.getDynamic(v);
|
||||
return t.kind == HEnum;
|
||||
}
|
||||
|
||||
public static function deleteField(o:Dynamic, field:String):Bool {
|
||||
return hl.Api.deleteField(o, @:privateAccess field.bytes.hash());
|
||||
}
|
||||
|
||||
@:hlNative("std", "obj_copy")
|
||||
public static function copy<T>(o:Null<T>):Null<T> {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:overload(function(f:Array<Dynamic>->Void):Dynamic {})
|
||||
extern public static function makeVarArgs(f:Array<Dynamic>->Dynamic):Dynamic;
|
||||
|
||||
@:ifFeature("Reflect.makeVarArgs") static function _makeVarArgs(f:Array<Dynamic>->Dynamic):Dynamic {
|
||||
return hl.Api.makeVarArgs(function(args:hl.NativeArray<Dynamic>) {
|
||||
var arr = hl.types.ArrayDyn.alloc(hl.types.ArrayObj.alloc(args), true);
|
||||
return f(cast arr);
|
||||
});
|
||||
}
|
||||
}
|
146
Kha/Tools/macos/std/hl/_std/Std.hx
Normal file
146
Kha/Tools/macos/std/hl/_std/Std.hx
Normal file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import hl.Boot;
|
||||
|
||||
private typedef Rand = hl.Abstract<"hl_random">;
|
||||
|
||||
@:coreApi
|
||||
class Std {
|
||||
static var rnd:Rand;
|
||||
static var toStringDepth:Int = 0;
|
||||
|
||||
static function __init__():Void {
|
||||
rnd = rnd_sys();
|
||||
}
|
||||
|
||||
@:hlNative("std", "rnd_init_system") static function rnd_sys():Rand {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "rnd_int") static function rnd_int(r:Rand):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative("std", "rnd_float") static function rnd_float(r:Rand):Float {
|
||||
return 0.;
|
||||
}
|
||||
|
||||
public static function random(x:Int):Int {
|
||||
return x <= 0 ? 0 : (rnd_int(rnd) & 0x3FFFFFFF) % x;
|
||||
}
|
||||
|
||||
@:deprecated('Std.is is deprecated. Use Std.isOfType instead.')
|
||||
public static inline function is(v:Dynamic, t:Dynamic):Bool {
|
||||
return isOfType(v, t);
|
||||
}
|
||||
|
||||
public static function isOfType(v:Dynamic, t:Dynamic):Bool {
|
||||
var t:hl.BaseType = t;
|
||||
if (t == null)
|
||||
return false;
|
||||
switch (t.__type__.kind) {
|
||||
case HDyn:
|
||||
return v != null;
|
||||
case HF64:
|
||||
switch (hl.Type.getDynamic(v).kind) {
|
||||
case HUI8, HUI16, HI32:
|
||||
return true;
|
||||
default:
|
||||
}
|
||||
case HI32:
|
||||
switch (hl.Type.getDynamic(v).kind) {
|
||||
case HF32, HF64:
|
||||
var v:Float = v;
|
||||
return Std.int(v) == v;
|
||||
default:
|
||||
}
|
||||
default:
|
||||
}
|
||||
return t.check(v);
|
||||
}
|
||||
|
||||
extern public static function downcast<T:{}, S:T>(value:T, c:Class<S>):S;
|
||||
|
||||
@:deprecated('Std.instance() is deprecated. Use Std.downcast() instead.')
|
||||
public static inline function instance<T:{}, S:T>(value:T, c:Class<S>):S {
|
||||
return downcast(value, c);
|
||||
}
|
||||
|
||||
extern public static inline function int(x:Float):Int {
|
||||
return untyped $int(x);
|
||||
}
|
||||
|
||||
@:keep public static function string(s:Dynamic):String {
|
||||
var len = 0;
|
||||
var bytes = hl.Bytes.fromValue(s, new hl.Ref(len));
|
||||
return @:privateAccess String.__alloc__(bytes, len);
|
||||
}
|
||||
|
||||
public static function parseInt(x:String):Null<Int> {
|
||||
if (x == null)
|
||||
return null;
|
||||
return @:privateAccess x.bytes.parseInt(0, x.length << 1);
|
||||
}
|
||||
|
||||
public static function parseFloat(x:String):Float {
|
||||
if (x == null)
|
||||
return Math.NaN;
|
||||
return @:privateAccess x.bytes.parseFloat(0, x.length << 1);
|
||||
}
|
||||
|
||||
@:keep static function __add__(a:Dynamic, b:Dynamic):Dynamic {
|
||||
var ta = hl.Type.getDynamic(a);
|
||||
var tb = hl.Type.getDynamic(b);
|
||||
if (ta == hl.Type.get(""))
|
||||
return (a : String) + b;
|
||||
if (tb == hl.Type.get(""))
|
||||
return a + (b : String);
|
||||
switch (ta.kind) {
|
||||
case HUI8, HUI16, HI32:
|
||||
var a:Int = a;
|
||||
switch (tb.kind) {
|
||||
case HUI8, HUI16, HI32: return a + (b : Int);
|
||||
case HF32, HF64: return a + (b : Float);
|
||||
case HVoid: return a;
|
||||
default:
|
||||
}
|
||||
case HF32, HF64:
|
||||
var a:Float = a;
|
||||
switch (tb.kind) {
|
||||
case HUI8, HUI16, HI32: return a + (b : Int);
|
||||
case HF32, HF64: return a + (b : Float);
|
||||
case HVoid: return a;
|
||||
default:
|
||||
}
|
||||
case HVoid:
|
||||
switch (tb.kind) {
|
||||
case HUI8, HUI16, HI32, HF32, HF64: return b;
|
||||
case HVoid: return 0.;
|
||||
default:
|
||||
}
|
||||
default:
|
||||
}
|
||||
throw "Can't add " + a + "(" + ta + ") and " + b + "(" + tb + ")";
|
||||
return null;
|
||||
}
|
||||
}
|
256
Kha/Tools/macos/std/hl/_std/String.hx
Normal file
256
Kha/Tools/macos/std/hl/_std/String.hx
Normal file
@ -0,0 +1,256 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
@:coreApi
|
||||
class String {
|
||||
var bytes:hl.Bytes;
|
||||
|
||||
public var length(default, null):Int;
|
||||
|
||||
public function new(string:String):Void {
|
||||
bytes = string.bytes;
|
||||
length = string.length;
|
||||
}
|
||||
|
||||
public function toUpperCase():String {
|
||||
return __alloc__(@:privateAccess bytes.ucs2Upper(0, length), length);
|
||||
}
|
||||
|
||||
public function toLowerCase():String {
|
||||
return __alloc__(@:privateAccess bytes.ucs2Lower(0, length), length);
|
||||
}
|
||||
|
||||
public function charAt(index:Int):String {
|
||||
if ((index : UInt) >= (length : UInt))
|
||||
return "";
|
||||
var b = new hl.Bytes(4);
|
||||
b.setUI16(0, bytes.getUI16(index << 1));
|
||||
b.setUI16(2, 0);
|
||||
return __alloc__(b, 1);
|
||||
}
|
||||
|
||||
public function charCodeAt(index:Int):Null<Int> {
|
||||
var idx:UInt = index;
|
||||
if (idx >= (length : UInt))
|
||||
return null;
|
||||
return bytes.getUI16(index << 1);
|
||||
}
|
||||
|
||||
inline function findChar(start:Int, len:Int, src:hl.Bytes, srcLen:Int):Int {
|
||||
var p = 0;
|
||||
while (true) {
|
||||
p = bytes.find(start, len - start, src, 0, srcLen);
|
||||
if (p < 0 || p & 1 == 0)
|
||||
break;
|
||||
start = p + 1;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
public function indexOf(str:String, ?startIndex:Int):Int {
|
||||
var startByte = 0;
|
||||
if (startIndex != null && startIndex > 0) {
|
||||
if (startIndex >= length)
|
||||
return str == '' ? length : -1;
|
||||
startByte = startIndex << 1;
|
||||
}
|
||||
var p = findChar(startByte, length << 1, str.bytes, str.length << 1);
|
||||
if (p > 0)
|
||||
p >>= 1;
|
||||
return p;
|
||||
}
|
||||
|
||||
public function lastIndexOf(str:String, ?startIndex:Int):Int {
|
||||
var max = this.length;
|
||||
if (startIndex != null) {
|
||||
max = startIndex + str.length;
|
||||
if (max < 0)
|
||||
max = 0;
|
||||
if (max > this.length)
|
||||
max = this.length;
|
||||
}
|
||||
var pos = max - str.length;
|
||||
var slen = str.length << 1;
|
||||
while (pos >= 0) {
|
||||
if (bytes.compare(pos << 1, str.bytes, 0, slen) == 0)
|
||||
return pos;
|
||||
pos--;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public function split(delimiter:String):Array<String> {
|
||||
var out = [];
|
||||
if (length == 0) {
|
||||
out.push("");
|
||||
return out;
|
||||
}
|
||||
if (delimiter.length == 0) {
|
||||
for (i in 0...length)
|
||||
out.push(substr(i, 1));
|
||||
return out;
|
||||
}
|
||||
var pos = 0;
|
||||
var dlen = delimiter.length;
|
||||
while (true) {
|
||||
var p = findChar(pos << 1, length << 1, delimiter.bytes, dlen << 1);
|
||||
if (p < 0) {
|
||||
out.push(substr(pos, length - pos));
|
||||
break;
|
||||
}
|
||||
p >>= 1;
|
||||
out.push(substr(pos, p - pos));
|
||||
pos = p + dlen;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public function substr(pos:Int, ?len:Int):String@:privateAccess {
|
||||
var sl = length;
|
||||
var len:Int = if (len == null) sl else len;
|
||||
if (len == 0)
|
||||
return "";
|
||||
if (pos != 0 && len < 0)
|
||||
return "";
|
||||
if (pos < 0) {
|
||||
pos = sl + pos;
|
||||
if (pos < 0)
|
||||
pos = 0;
|
||||
} else if (len < 0) {
|
||||
len = sl + len - pos;
|
||||
if (len < 0)
|
||||
return "";
|
||||
}
|
||||
if (((pos + len) : UInt) > (sl : UInt))
|
||||
len = sl - pos;
|
||||
if (pos < 0 || len <= 0)
|
||||
return "";
|
||||
|
||||
var b = new hl.Bytes((len + 1) << 1);
|
||||
b.blit(0, bytes, pos << 1, len << 1);
|
||||
b.setUI16(len << 1, 0);
|
||||
return __alloc__(b, len);
|
||||
}
|
||||
|
||||
public function substring(startIndex:Int, ?endIndex:Int):String {
|
||||
var end:Int;
|
||||
if (endIndex == null)
|
||||
end = length;
|
||||
else {
|
||||
end = endIndex;
|
||||
if (end < 0)
|
||||
end = 0;
|
||||
else if (end > length)
|
||||
end = length;
|
||||
}
|
||||
if (startIndex < 0)
|
||||
startIndex = 0;
|
||||
else if (startIndex > length)
|
||||
startIndex = length;
|
||||
if (startIndex > end) {
|
||||
var tmp = startIndex;
|
||||
startIndex = end;
|
||||
end = tmp;
|
||||
}
|
||||
return substr(startIndex, end - startIndex);
|
||||
}
|
||||
|
||||
public function toString():String {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static function fromCharCode(code:Int):String {
|
||||
if (code >= 0 && code < 0x10000) {
|
||||
if (code >= 0xD800 && code <= 0xDFFF)
|
||||
throw "Invalid unicode char " + code;
|
||||
var b = new hl.Bytes(4);
|
||||
b.setUI16(0, code);
|
||||
b.setUI16(2, 0);
|
||||
return __alloc__(b, 1);
|
||||
} else if (code < 0x110000) {
|
||||
var b = new hl.Bytes(6);
|
||||
code -= 0x10000;
|
||||
b.setUI16(0, (code >> 10) + 0xD800);
|
||||
b.setUI16(2, (code & 1023) + 0xDC00);
|
||||
b.setUI16(4, 0);
|
||||
return __alloc__(b, 2); // UTF16 encoding but UCS2 API (same as JS)
|
||||
} else
|
||||
throw "Invalid unicode char " + code;
|
||||
}
|
||||
|
||||
function toUtf8():hl.Bytes {
|
||||
return bytes.utf16ToUtf8(0, null);
|
||||
}
|
||||
|
||||
@:keep function __string():hl.Bytes {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@:keep function __compare(v:Dynamic):Int {
|
||||
var s = Std.downcast(v, String);
|
||||
if (s == null)
|
||||
return hl.Api.comparePointer(this, v);
|
||||
#if (hl_ver >= version("1.10.0"))
|
||||
var v = bytes.compare16(s.bytes, length < s.length ? length : s.length);
|
||||
#else
|
||||
var v = bytes.compare(0, s.bytes, 0, (length < s.length ? length : s.length) << 1);
|
||||
#end
|
||||
return v == 0 ? length - s.length : v;
|
||||
}
|
||||
|
||||
@:keep static inline function __alloc__(b:hl.Bytes, length:Int):String {
|
||||
var s:String = untyped $new(String);
|
||||
s.bytes = b;
|
||||
s.length = length;
|
||||
return s;
|
||||
}
|
||||
|
||||
@:keep static function call_toString(v:Dynamic):hl.Bytes {
|
||||
var s:String = v.toString();
|
||||
return s.bytes;
|
||||
}
|
||||
|
||||
inline static function fromUCS2(b:hl.Bytes):String {
|
||||
var s:String = untyped $new(String);
|
||||
s.bytes = b;
|
||||
s.length = @:privateAccess b.ucs2Length(0);
|
||||
return s;
|
||||
}
|
||||
|
||||
@:keep static function fromUTF8(b:hl.Bytes):String {
|
||||
var outLen = 0;
|
||||
var b2 = @:privateAccess b.utf8ToUtf16(0, outLen);
|
||||
return __alloc__(b2, outLen >> 1);
|
||||
}
|
||||
|
||||
@:keep static function __add__(a:String, b:String):String {
|
||||
if (a == null)
|
||||
a = "null";
|
||||
if (b == null)
|
||||
b = "null";
|
||||
var asize = a.length << 1, bsize = b.length << 1, tot = asize + bsize;
|
||||
var bytes = new hl.Bytes(tot + 2);
|
||||
bytes.blit(0, a.bytes, 0, asize);
|
||||
bytes.blit(asize, b.bytes, 0, bsize);
|
||||
bytes.setUI16(tot, 0);
|
||||
return __alloc__(bytes, tot >> 1);
|
||||
}
|
||||
}
|
110
Kha/Tools/macos/std/hl/_std/StringBuf.hx
Normal file
110
Kha/Tools/macos/std/hl/_std/StringBuf.hx
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
@:coreApi class StringBuf {
|
||||
var b:hl.Bytes;
|
||||
var size:Int;
|
||||
var pos:Int;
|
||||
|
||||
public var length(get, never):Int;
|
||||
|
||||
public function new():Void {
|
||||
pos = 0;
|
||||
size = 8; // ensure 4 bytes expand for addChar()
|
||||
b = new hl.Bytes(size);
|
||||
}
|
||||
|
||||
inline function get_length():Int {
|
||||
return pos >> 1;
|
||||
}
|
||||
|
||||
inline function __expand(need:Int):Void {
|
||||
var nsize = (size * 3) >> 1;
|
||||
if (need > nsize)
|
||||
nsize = need;
|
||||
var b2 = new hl.Bytes(nsize);
|
||||
b2.blit(0, b, 0, pos);
|
||||
b = b2;
|
||||
size = nsize;
|
||||
}
|
||||
|
||||
inline function __add(bytes:hl.Bytes, spos:Int, ssize:Int):Void {
|
||||
if (pos + ssize > size)
|
||||
__expand(pos + ssize);
|
||||
b.blit(pos, bytes, spos, ssize);
|
||||
pos += ssize;
|
||||
}
|
||||
|
||||
public function add<T>(x:T):Void {
|
||||
var slen = 0;
|
||||
var str = Std.downcast((x:Dynamic),String);
|
||||
if( str != null ) {
|
||||
__add(@:privateAccess str.bytes, 0, str.length<<1);
|
||||
return;
|
||||
}
|
||||
var sbytes = hl.Bytes.fromValue(x, new hl.Ref(slen));
|
||||
__add(sbytes, 0, slen << 1);
|
||||
}
|
||||
|
||||
public function addSub(s:String, pos:Int, ?len:Int):Void@:privateAccess {
|
||||
if (pos < 0)
|
||||
pos = 0;
|
||||
if (pos >= s.length)
|
||||
return;
|
||||
var slen:Int;
|
||||
if (len == null)
|
||||
slen = s.length - pos
|
||||
else {
|
||||
slen = len;
|
||||
if (pos + slen > s.length)
|
||||
slen = s.length - pos;
|
||||
if (slen <= 0)
|
||||
return;
|
||||
}
|
||||
__add(s.bytes, pos << 1, slen << 1);
|
||||
}
|
||||
|
||||
public function addChar(c:Int):Void {
|
||||
if (c >= 0 && c < 0x10000) {
|
||||
if (c >= 0xD800 && c <= 0xDFFF)
|
||||
throw "Invalid unicode char " + c;
|
||||
if (pos + 2 > size)
|
||||
__expand(0);
|
||||
b.setUI16(pos, c);
|
||||
pos += 2;
|
||||
} else if (c < 0x110000) {
|
||||
if (pos + 4 > size)
|
||||
__expand(0);
|
||||
c -= 0x10000;
|
||||
b.setUI16(pos, (c >> 10) + 0xD800);
|
||||
b.setUI16(pos + 2, (c & 1023) + 0xDC00);
|
||||
pos += 4;
|
||||
} else
|
||||
throw "Invalid unicode char " + c;
|
||||
}
|
||||
|
||||
public function toString():String {
|
||||
if (pos + 2 > size)
|
||||
__expand(0);
|
||||
b.setUI16(pos, 0);
|
||||
return @:privateAccess String.__alloc__(b, pos >> 1);
|
||||
}
|
||||
}
|
235
Kha/Tools/macos/std/hl/_std/Sys.hx
Normal file
235
Kha/Tools/macos/std/hl/_std/Sys.hx
Normal file
@ -0,0 +1,235 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import haxe.SysTools;
|
||||
|
||||
class SysError {
|
||||
public var msg:String;
|
||||
|
||||
public function new(msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
@:keep public function toString() {
|
||||
return "SysError(" + msg + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@:coreApi
|
||||
@:keepInit
|
||||
@:access(String)
|
||||
class Sys {
|
||||
static var utf8Path:Bool;
|
||||
|
||||
static function __init__():Void {
|
||||
utf8Path = sys_utf8_path();
|
||||
}
|
||||
|
||||
static function getPath(s:String):hl.Bytes {
|
||||
return utf8Path ? s.bytes.utf16ToUtf8(0, null) : s.bytes;
|
||||
}
|
||||
|
||||
static function makePath(b:hl.Bytes):String {
|
||||
if (b == null)
|
||||
return null;
|
||||
return utf8Path ? String.fromUTF8(b) : String.fromUCS2(b);
|
||||
}
|
||||
|
||||
public static function print(v:Dynamic):Void {
|
||||
sys_print(Std.string(v).bytes);
|
||||
}
|
||||
|
||||
public static function println(v:Dynamic):Void {
|
||||
sys_print(Std.string(v).bytes);
|
||||
sys_print("\n".bytes);
|
||||
}
|
||||
|
||||
public static function args():Array<String> {
|
||||
return [for (a in sys_args()) makePath(a)];
|
||||
}
|
||||
|
||||
public static function stdin():haxe.io.Input {
|
||||
return @:privateAccess new sys.io.FileInput(file_stdin());
|
||||
}
|
||||
|
||||
public static function stdout():haxe.io.Output {
|
||||
return @:privateAccess new sys.io.FileOutput(file_stdout());
|
||||
}
|
||||
|
||||
public static function stderr():haxe.io.Output {
|
||||
return @:privateAccess new sys.io.FileOutput(file_stderr());
|
||||
}
|
||||
|
||||
public static function getEnv(s:String):String {
|
||||
var v = get_env(getPath(s));
|
||||
if (v == null)
|
||||
return null;
|
||||
return makePath(v);
|
||||
}
|
||||
|
||||
public static function putEnv(s:String, v:String):Void {
|
||||
if (!put_env(getPath(s), if (v == null) null else getPath(v)))
|
||||
throw "putEnv() failure";
|
||||
}
|
||||
|
||||
public static function environment():Map<String, String> {
|
||||
var env = sys_env();
|
||||
var h = new haxe.ds.StringMap();
|
||||
for (i in 0...env.length >> 1) {
|
||||
var p = i << 1;
|
||||
h.set(makePath(env[p]), makePath(env[p + 1]));
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_sleep")
|
||||
public static function sleep(seconds:Float):Void {}
|
||||
|
||||
public static function setTimeLocale(loc:String):Bool {
|
||||
return set_time_locale(loc.bytes.utf16ToUtf8(0, null));
|
||||
}
|
||||
|
||||
public static function getCwd():String {
|
||||
return makePath(get_cwd());
|
||||
}
|
||||
|
||||
public static function setCwd(s:String):Void {
|
||||
if (!set_cwd(getPath(s)))
|
||||
throw new SysError("Failed to set path to " + s);
|
||||
}
|
||||
|
||||
public static function systemName():String {
|
||||
return String.fromUCS2(sys_string());
|
||||
}
|
||||
|
||||
public static function command(cmd:String, ?args:Array<String>):Int {
|
||||
var code = 0;
|
||||
if (args == null) {
|
||||
code = sys_command(getPath(cmd));
|
||||
} else {
|
||||
switch (systemName()) {
|
||||
case "Windows":
|
||||
cmd = [
|
||||
for (a in [StringTools.replace(cmd, "/", "\\")].concat(args))
|
||||
SysTools.quoteWinArg(a, true)
|
||||
].join(" ");
|
||||
code = sys_command(getPath(cmd));
|
||||
case _:
|
||||
cmd = [cmd].concat(args).map(SysTools.quoteUnixArg).join(" ");
|
||||
code = sys_command(getPath(cmd));
|
||||
}
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
@:deprecated("Use programPath instead") public static function executablePath():String {
|
||||
return makePath(sys_exe_path());
|
||||
}
|
||||
|
||||
public static function programPath():String {
|
||||
return sys_program_path;
|
||||
}
|
||||
|
||||
private static var sys_program_path = {
|
||||
var hlFile = sys_hl_file();
|
||||
if (hlFile == null)
|
||||
makePath(sys_exe_path());
|
||||
else
|
||||
sys.FileSystem.fullPath(makePath(hlFile));
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_utf8_path") static function sys_utf8_path():Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_time") public static function time():Float {
|
||||
return 0.;
|
||||
};
|
||||
|
||||
@:hlNative("std", "sys_exit") public static function exit(code:Int):Void {};
|
||||
|
||||
@:hlNative("std", "sys_cpu_time") public static function cpuTime():Float {
|
||||
return 0.;
|
||||
};
|
||||
|
||||
@:hlNative("std", "sys_get_char") public static function getChar(echo:Bool):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_print") static function sys_print(v:hl.Bytes):Void {};
|
||||
|
||||
@:hlNative("std", "file_stdin") static function file_stdin():sys.io.File.FileHandle {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "file_stdout") static function file_stdout():sys.io.File.FileHandle {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "file_stderr") static function file_stderr():sys.io.File.FileHandle {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_args") static function sys_args():hl.NativeArray<hl.Bytes> {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_get_env") static function get_env(key:hl.Bytes):hl.Bytes {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_put_env") static function put_env(key:hl.Bytes, val:hl.Bytes):Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_env") static function sys_env():hl.NativeArray<hl.Bytes> {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_set_time_locale") static function set_time_locale(loc:hl.Bytes):Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_get_cwd") static function get_cwd():hl.Bytes {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_set_cwd") static function set_cwd(path:hl.Bytes):Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_command") static function sys_command(cmd:hl.Bytes):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_exe_path") static function sys_exe_path():hl.Bytes {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_hl_file") static function sys_hl_file():hl.Bytes {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_string") static function sys_string():hl.Bytes {
|
||||
return null;
|
||||
}
|
||||
}
|
267
Kha/Tools/macos/std/hl/_std/Type.hx
Normal file
267
Kha/Tools/macos/std/hl/_std/Type.hx
Normal file
@ -0,0 +1,267 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
enum ValueType {
|
||||
TNull;
|
||||
TInt;
|
||||
TFloat;
|
||||
TBool;
|
||||
TObject;
|
||||
TFunction;
|
||||
TClass(c:Class<Dynamic>);
|
||||
TEnum(e:Enum<Dynamic>);
|
||||
TUnknown;
|
||||
}
|
||||
|
||||
@:coreApi
|
||||
class Type {
|
||||
static var allTypes(get, never):hl.types.BytesMap;
|
||||
|
||||
static inline function get_allTypes():hl.types.BytesMap
|
||||
return untyped $allTypes();
|
||||
|
||||
@:keep static function init():Void {
|
||||
untyped $allTypes(new hl.types.BytesMap());
|
||||
}
|
||||
|
||||
@:keep static function initClass(ct:hl.Type, t:hl.Type, name:hl.Bytes):hl.BaseType.Class@:privateAccess {
|
||||
var c:hl.BaseType.Class = ct.allocObject();
|
||||
t.setGlobal(c);
|
||||
c.__type__ = t;
|
||||
c.__name__ = String.fromUCS2(name);
|
||||
register(name, c);
|
||||
return c;
|
||||
}
|
||||
|
||||
@:keep static function initEnum(et:hl.Type, t:hl.Type):hl.BaseType.Enum@:privateAccess {
|
||||
var e:hl.BaseType.Enum = et.allocObject();
|
||||
e.__type__ = t;
|
||||
e.__evalues__ = t.getEnumValues();
|
||||
e.__ename__ = t.getTypeName();
|
||||
e.__emap__ = new hl.types.BytesMap();
|
||||
e.__constructs__ = new Array();
|
||||
var cl = t.getEnumFields();
|
||||
for (i in 0...cl.length) {
|
||||
var name = cl[i];
|
||||
e.__emap__.set(name, i);
|
||||
e.__constructs__.push(String.fromUCS2(name));
|
||||
}
|
||||
register(e.__ename__.bytes, e);
|
||||
t.setGlobal(e);
|
||||
return e;
|
||||
}
|
||||
|
||||
@:keep static function register(b:hl.Bytes, t:hl.BaseType):Void {
|
||||
allTypes.set(b, t);
|
||||
}
|
||||
|
||||
public static function getClass<T>(o:T):Class<T> {
|
||||
var t = hl.Type.getDynamic(o);
|
||||
if (t.kind == HVirtual) {
|
||||
o = hl.Api.getVirtualValue(o);
|
||||
t = hl.Type.getDynamic(o);
|
||||
}
|
||||
if (t.kind == HObj)
|
||||
return t.getGlobal();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getEnum(o:EnumValue):Enum<Dynamic> {
|
||||
var t = hl.Type.getDynamic(o);
|
||||
if (t.kind == HEnum)
|
||||
return t.getGlobal();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getSuperClass(c:Class<Dynamic>):Class<Dynamic>@:privateAccess {
|
||||
var c:hl.BaseType.Class = cast c;
|
||||
var t = c.__type__.getSuper();
|
||||
return t == hl.Type.void() ? null : t.getGlobal();
|
||||
}
|
||||
|
||||
public static function getClassName(c:Class<Dynamic>):String {
|
||||
var c:hl.BaseType.Class = cast c;
|
||||
return c.__name__;
|
||||
}
|
||||
|
||||
public static function getEnumName(e:Enum<Dynamic>):String {
|
||||
var e:hl.BaseType.Enum = cast e;
|
||||
return e.__ename__;
|
||||
}
|
||||
|
||||
public static function resolveClass(name:String):Class<Dynamic> {
|
||||
var t:hl.BaseType = allTypes.get(@:privateAccess name.bytes);
|
||||
if (t == null || !Std.isOfType(t, hl.BaseType.Class))
|
||||
return null;
|
||||
return cast t;
|
||||
}
|
||||
|
||||
public static function resolveEnum(name:String):Enum<Dynamic> {
|
||||
var t:hl.BaseType = allTypes.get(@:privateAccess name.bytes);
|
||||
if (t == null || !Std.isOfType(t, hl.BaseType.Enum))
|
||||
return null;
|
||||
return cast t;
|
||||
}
|
||||
|
||||
public static function createInstance<T>(cl:Class<T>, args:Array<Dynamic>):T {
|
||||
var c:hl.BaseType.Class = cast cl;
|
||||
var t = c.__type__;
|
||||
if (t == hl.Type.get((null : hl.types.ArrayBase.ArrayAccess)))
|
||||
return cast new Array<Dynamic>();
|
||||
var o = t.allocObject();
|
||||
if (c.__constructor__ != null) {
|
||||
var v:Dynamic = hl.Api.noClosure(c.__constructor__);
|
||||
var args = args.copy();
|
||||
args.unshift(o);
|
||||
Reflect.callMethod(null, v, args);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
public static function createEmptyInstance<T>(cl:Class<T>):T {
|
||||
var c:hl.BaseType.Class = cast cl;
|
||||
return c.__type__.allocObject();
|
||||
}
|
||||
|
||||
public static function createEnum<T>(e:Enum<T>, constr:String, ?params:Array<Dynamic>):T {
|
||||
var en:hl.BaseType.Enum = cast e;
|
||||
var idx:Null<Int> = en.__emap__.get(@:privateAccess constr.bytes);
|
||||
if (idx == null)
|
||||
throw "Unknown enum constructor " + en.__ename__ + "." + constr;
|
||||
return createEnumIndex(e, idx, params);
|
||||
}
|
||||
|
||||
public static function createEnumIndex<T>(e:Enum<T>, index:Int, ?params:Array<Dynamic>):T {
|
||||
var e:hl.BaseType.Enum = cast e;
|
||||
if (index < 0 || index >= e.__constructs__.length)
|
||||
throw "Invalid enum index " + e.__ename__ + "." + index;
|
||||
if (params == null || params.length == 0) {
|
||||
var v = index >= e.__evalues__.length ? null : e.__evalues__[index];
|
||||
if (v == null)
|
||||
throw "Constructor " + e.__ename__ + "." + e.__constructs__[index] + " takes parameters";
|
||||
return v;
|
||||
}
|
||||
var a:hl.types.ArrayDyn = cast params;
|
||||
var narr;
|
||||
if (@:privateAccess !a.array.isArrayObj()) {
|
||||
narr = new hl.NativeArray<Dynamic>(a.length);
|
||||
for (i in 0...a.length)
|
||||
narr[i] = @:privateAccess a.array.getDyn(i);
|
||||
} else {
|
||||
var aobj:hl.types.ArrayObj<Dynamic> = cast @:privateAccess a.array;
|
||||
narr = @:privateAccess aobj.array;
|
||||
}
|
||||
var v = @:privateAccess e.__type__.allocEnum(index, narr, a.length);
|
||||
if (v == null)
|
||||
throw "Constructor " + e.__ename__ + "." + e.__constructs__[index] + " does not takes " + narr.length + " parameters";
|
||||
return v;
|
||||
}
|
||||
|
||||
public static function getInstanceFields(c:Class<Dynamic>):Array<String>@:privateAccess {
|
||||
var c:hl.BaseType.Class = cast c;
|
||||
var fields = c.__type__.getInstanceFields();
|
||||
return [for (f in fields) String.fromUCS2(f)];
|
||||
}
|
||||
|
||||
public static function getClassFields(c:Class<Dynamic>):Array<String> {
|
||||
var c:hl.BaseType.Class = cast c;
|
||||
var fields = @:privateAccess Reflect.getObjectFields(c);
|
||||
var fields = [for (f in fields) @:privateAccess String.fromUCS2(f)];
|
||||
fields.remove("__constructor__");
|
||||
fields.remove("__meta__");
|
||||
fields.remove("__name__");
|
||||
fields.remove("__type__");
|
||||
fields.remove("__implementedBy__");
|
||||
return fields;
|
||||
}
|
||||
|
||||
public static function getEnumConstructs(e:Enum<Dynamic>):Array<String> {
|
||||
var e:hl.BaseType.Enum = cast e;
|
||||
return e.__constructs__.copy();
|
||||
}
|
||||
|
||||
public static function typeof(v:Dynamic):ValueType {
|
||||
var t = hl.Type.getDynamic(v);
|
||||
switch (t.kind) {
|
||||
case HVoid:
|
||||
return TNull;
|
||||
case HUI8, HUI16, HI32:
|
||||
return TInt;
|
||||
case HF32, HF64:
|
||||
return (v : Int) == (v:Float) ? TInt : TFloat;
|
||||
case HBool:
|
||||
return TBool;
|
||||
case HDynObj:
|
||||
return TObject;
|
||||
case HObj:
|
||||
var c:Dynamic = Type.getClass(v);
|
||||
if (c == Class || c == null)
|
||||
return TObject;
|
||||
return TClass(c);
|
||||
case HEnum:
|
||||
return TEnum(Type.getEnum(v));
|
||||
case HFun:
|
||||
return TFunction;
|
||||
case HVirtual:
|
||||
var v = hl.Api.getVirtualValue(v);
|
||||
if (v == null)
|
||||
return TObject;
|
||||
return typeof(v);
|
||||
default:
|
||||
return TUnknown;
|
||||
}
|
||||
}
|
||||
|
||||
@:hlNative("std", "type_enum_eq")
|
||||
public static function enumEq<T:EnumValue>(a:T, b:T):Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function enumConstructor(e:EnumValue):String {
|
||||
var en:hl.BaseType.Enum = cast getEnum(e);
|
||||
return en.__constructs__[Type.enumIndex(e)];
|
||||
}
|
||||
|
||||
@:hlNative("std", "enum_parameters")
|
||||
static function _enumParameters(e:EnumValue):hl.NativeArray<Dynamic> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function enumParameters(e:EnumValue):Array<Dynamic> {
|
||||
var arr = _enumParameters(e);
|
||||
return cast hl.types.ArrayObj.alloc(arr);
|
||||
}
|
||||
|
||||
public static function enumIndex(e:EnumValue):Int {
|
||||
return untyped $enumIndex(e);
|
||||
}
|
||||
|
||||
public static function allEnums<T>(e:Enum<T>):Array<T> {
|
||||
var en:hl.BaseType.Enum = cast e;
|
||||
var out = [];
|
||||
for (i in 0...en.__evalues__.length) {
|
||||
var v = en.__evalues__[i];
|
||||
if (v != null)
|
||||
out.push(v);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
179
Kha/Tools/macos/std/hl/_std/UInt.hx
Normal file
179
Kha/Tools/macos/std/hl/_std/UInt.hx
Normal file
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
@:coreApi
|
||||
@:transitive
|
||||
abstract UInt(Int) from Int to Int {
|
||||
@:op(A + B) private static inline function add(a:UInt, b:UInt):UInt {
|
||||
return a.toInt() + b.toInt();
|
||||
}
|
||||
|
||||
@:op(A / B) private static inline function div(a:UInt, b:UInt):Float {
|
||||
return a.toFloat() / b.toFloat();
|
||||
}
|
||||
|
||||
@:op(A * B) private static inline function mul(a:UInt, b:UInt):UInt {
|
||||
return a.toInt() * b.toInt();
|
||||
}
|
||||
|
||||
@:op(A - B) private static inline function sub(a:UInt, b:UInt):UInt {
|
||||
return a.toInt() - b.toInt();
|
||||
}
|
||||
|
||||
@:op(A > B) private static function gt(a:UInt, b:UInt):Bool;
|
||||
|
||||
@:op(A >= B) private static function gte(a:UInt, b:UInt):Bool;
|
||||
|
||||
@:op(A < B) private static function lt(a:UInt, b:UInt):Bool;
|
||||
|
||||
@:op(A <= B) private static function lte(a:UInt, b:UInt):Bool;
|
||||
|
||||
@:op(A & B) private static inline function and(a:UInt, b:UInt):UInt {
|
||||
return a.toInt() & b.toInt();
|
||||
}
|
||||
|
||||
@:op(A | B) private static inline function or(a:UInt, b:UInt):UInt {
|
||||
return a.toInt() | b.toInt();
|
||||
}
|
||||
|
||||
@:op(A ^ B) private static inline function xor(a:UInt, b:UInt):UInt {
|
||||
return a.toInt() ^ b.toInt();
|
||||
}
|
||||
|
||||
@:op(A << B) private static inline function shl(a:UInt, b:Int):UInt {
|
||||
return a.toInt() << b;
|
||||
}
|
||||
|
||||
@:op(A >> B) private static inline function shr(a:UInt, b:Int):UInt {
|
||||
return a.toInt() >>> b;
|
||||
}
|
||||
|
||||
@:op(A >>> B) private static inline function ushr(a:UInt, b:Int):UInt {
|
||||
return a.toInt() >>> b;
|
||||
}
|
||||
|
||||
@:op(A % B) private static function mod(a:UInt, b:UInt):UInt;
|
||||
|
||||
@:commutative @:op(A + B) private static inline function addWithFloat(a:UInt, b:Float):Float {
|
||||
return a.toFloat() + b;
|
||||
}
|
||||
|
||||
@:commutative @:op(A * B) private static inline function mulWithFloat(a:UInt, b:Float):Float {
|
||||
return a.toFloat() * b;
|
||||
}
|
||||
|
||||
@:op(A / B) private static inline function divFloat(a:UInt, b:Float):Float {
|
||||
return a.toFloat() / b;
|
||||
}
|
||||
|
||||
@:op(A / B) private static inline function floatDiv(a:Float, b:UInt):Float {
|
||||
return a / b.toFloat();
|
||||
}
|
||||
|
||||
@:op(A - B) private static inline function subFloat(a:UInt, b:Float):Float {
|
||||
return a.toFloat() - b;
|
||||
}
|
||||
|
||||
@:op(A - B) private static inline function floatSub(a:Float, b:UInt):Float {
|
||||
return a - b.toFloat();
|
||||
}
|
||||
|
||||
@:op(A > B) private static inline function gtFloat(a:UInt, b:Float):Bool {
|
||||
return a.toFloat() > b;
|
||||
}
|
||||
|
||||
@:commutative @:op(A == B) private static function equalsInt<T:Int>(a:UInt, b:T):Bool;
|
||||
|
||||
@:commutative @:op(A != B) private static function notEqualsInt<T:Int>(a:UInt, b:T):Bool;
|
||||
|
||||
@:commutative @:op(A == B) private static function equalsFloat<T:Float>(a:UInt, b:T):Bool;
|
||||
|
||||
@:commutative @:op(A != B) private static function notEqualsFloat<T:Float>(a:UInt, b:T):Bool;
|
||||
|
||||
@:op(A >= B) private static inline function gteFloat(a:UInt, b:Float):Bool {
|
||||
return a.toFloat() >= b;
|
||||
}
|
||||
|
||||
@:op(A > B) private static inline function floatGt(a:Float, b:UInt):Bool {
|
||||
return a > b.toFloat();
|
||||
}
|
||||
|
||||
@:op(A >= B) private static inline function floatGte(a:Float, b:UInt):Bool {
|
||||
return a >= b.toFloat();
|
||||
}
|
||||
|
||||
@:op(A < B) private static inline function ltFloat(a:UInt, b:Float):Bool {
|
||||
return a.toFloat() < b;
|
||||
}
|
||||
|
||||
@:op(A <= B) private static inline function lteFloat(a:UInt, b:Float):Bool {
|
||||
return a.toFloat() <= b;
|
||||
}
|
||||
|
||||
@:op(A < B) private static inline function floatLt(a:Float, b:UInt):Bool {
|
||||
return a < b.toFloat();
|
||||
}
|
||||
|
||||
@:op(A <= B) private static inline function floatLte(a:Float, b:UInt):Bool {
|
||||
return a <= b.toFloat();
|
||||
}
|
||||
|
||||
@:op(A % B) private static inline function modFloat(a:UInt, b:Float):Float {
|
||||
return a.toFloat() % b;
|
||||
}
|
||||
|
||||
@:op(A % B) private static inline function floatMod(a:Float, b:UInt):Float {
|
||||
return a % b.toFloat();
|
||||
}
|
||||
|
||||
@:op(~A) private inline function negBits():UInt {
|
||||
return ~this;
|
||||
}
|
||||
|
||||
@:op(++A) private inline function prefixIncrement():UInt {
|
||||
return ++this;
|
||||
}
|
||||
|
||||
@:op(A++) private inline function postfixIncrement():UInt {
|
||||
return this++;
|
||||
}
|
||||
|
||||
@:op(--A) private inline function prefixDecrement():UInt {
|
||||
return --this;
|
||||
}
|
||||
|
||||
@:op(A--) private inline function postfixDecrement():UInt {
|
||||
return this--;
|
||||
}
|
||||
|
||||
// TODO: radix is just defined to deal with doc_gen issues
|
||||
private inline function toString(?radix:Int):String {
|
||||
return Std.string(toFloat());
|
||||
}
|
||||
|
||||
private inline function toInt():Int {
|
||||
return this;
|
||||
}
|
||||
|
||||
@:to private inline function toFloat():Float {
|
||||
return cast(this : UInt);
|
||||
}
|
||||
}
|
83
Kha/Tools/macos/std/hl/_std/haxe/Exception.hx
Normal file
83
Kha/Tools/macos/std/hl/_std/haxe/Exception.hx
Normal file
@ -0,0 +1,83 @@
|
||||
package haxe;
|
||||
|
||||
@:coreApi
|
||||
class Exception {
|
||||
public var message(get,never):String;
|
||||
public var stack(get,never):CallStack;
|
||||
public var previous(get,never):Null<Exception>;
|
||||
public var native(get,never):Any;
|
||||
|
||||
@:noCompletion var __exceptionMessage:String;
|
||||
@:noCompletion var __exceptionStack:Null<CallStack>;
|
||||
@:noCompletion var __nativeStack:hl.NativeArray<hl.Bytes>;
|
||||
@:noCompletion @:ifFeature("haxe.Exception.get_stack") var __skipStack:Int = 0;
|
||||
@:noCompletion var __nativeException:Any;
|
||||
@:noCompletion var __previousException:Null<Exception>;
|
||||
|
||||
static function caught(value:Any):Exception {
|
||||
if(Std.isOfType(value, Exception)) {
|
||||
return value;
|
||||
} else {
|
||||
return new ValueException(value, null, value);
|
||||
}
|
||||
}
|
||||
|
||||
static function thrown(value:Any):Any {
|
||||
if(Std.isOfType(value, Exception)) {
|
||||
return (value:Exception).native;
|
||||
} else {
|
||||
var e = new ValueException(value);
|
||||
e.__shiftStack();
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
public function new(message:String, ?previous:Exception, ?native:Any) {
|
||||
__exceptionMessage = message;
|
||||
__previousException = previous;
|
||||
if(native != null) {
|
||||
__nativeStack = NativeStackTrace.exceptionStack();
|
||||
__nativeException = native;
|
||||
} else {
|
||||
__nativeStack = NativeStackTrace.callStack();
|
||||
__nativeException = this;
|
||||
}
|
||||
}
|
||||
|
||||
function unwrap():Any {
|
||||
return __nativeException;
|
||||
}
|
||||
|
||||
public function toString():String {
|
||||
return message;
|
||||
}
|
||||
|
||||
public function details():String {
|
||||
return inline CallStack.exceptionToString(this);
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
@:ifFeature("haxe.Exception.get_stack")
|
||||
inline function __shiftStack():Void {
|
||||
__skipStack++;
|
||||
}
|
||||
|
||||
function get_message():String {
|
||||
return __exceptionMessage;
|
||||
}
|
||||
|
||||
function get_previous():Null<Exception> {
|
||||
return __previousException;
|
||||
}
|
||||
|
||||
final function get_native():Any {
|
||||
return __nativeException;
|
||||
}
|
||||
|
||||
function get_stack():CallStack {
|
||||
return switch __exceptionStack {
|
||||
case null: __exceptionStack = NativeStackTrace.toHaxe(__nativeStack, __skipStack);
|
||||
case s: s;
|
||||
}
|
||||
}
|
||||
}
|
58
Kha/Tools/macos/std/hl/_std/haxe/NativeStackTrace.hx
Normal file
58
Kha/Tools/macos/std/hl/_std/haxe/NativeStackTrace.hx
Normal file
@ -0,0 +1,58 @@
|
||||
package haxe;
|
||||
|
||||
import hl.NativeArray;
|
||||
import hl.Bytes;
|
||||
import haxe.CallStack.StackItem;
|
||||
|
||||
/**
|
||||
Do not use manually.
|
||||
**/
|
||||
@:dox(hide)
|
||||
@:noCompletion
|
||||
class NativeStackTrace {
|
||||
@:ifFeature('haxe.NativeStackTrace.exceptionStack')
|
||||
static public inline function saveStack(exception:Any):Void {
|
||||
}
|
||||
|
||||
@:hlNative("std", "exception_stack")
|
||||
static public function exceptionStack():NativeArray<Bytes> {
|
||||
return null;
|
||||
}
|
||||
|
||||
//TODO: implement in hashlink like `exceptionStack`
|
||||
static public function callStack():NativeArray<Bytes> {
|
||||
var stack:NativeArray<Bytes> = try {
|
||||
throw new Exception('', null, 'stack');
|
||||
} catch (e:Exception) {
|
||||
exceptionStack();
|
||||
}
|
||||
var skip = 1;
|
||||
for(i in 0...stack.length - 1) {
|
||||
var s = @:privateAccess String.fromUCS2(stack[i]);
|
||||
if(s.indexOf('NativeStackTrace.callStack') < 0) {
|
||||
break;
|
||||
}
|
||||
skip++;
|
||||
}
|
||||
return skip < stack.length ? stack.sub(skip, stack.length - skip) : stack;
|
||||
}
|
||||
|
||||
static public function toHaxe(native:NativeArray<Bytes>, skip:Int = 0):Array<StackItem> {
|
||||
var stack = [];
|
||||
var r = ~/^([A-Za-z0-9.$_]+)\.([~A-Za-z0-9_]+(\.[0-9]+)?)\((.+):([0-9]+)\)$/;
|
||||
var r_fun = ~/^fun\$([0-9]+)\((.+):([0-9]+)\)$/;
|
||||
for (i in 0...native.length - 1) {
|
||||
if(skip > i) {
|
||||
continue;
|
||||
}
|
||||
var str = @:privateAccess String.fromUCS2(native[i]);
|
||||
if (r.match(str))
|
||||
stack.push(FilePos(Method(r.matched(1), r.matched(2)), r.matched(4), Std.parseInt(r.matched(5))));
|
||||
else if (r_fun.match(str))
|
||||
stack.push(FilePos(LocalFunction(Std.parseInt(r_fun.matched(1))), r_fun.matched(2), Std.parseInt(r_fun.matched(3))));
|
||||
else
|
||||
stack.push(Module(str));
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
}
|
56
Kha/Tools/macos/std/hl/_std/haxe/Resource.hx
Normal file
56
Kha/Tools/macos/std/hl/_std/haxe/Resource.hx
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe;
|
||||
|
||||
private class ResourceContent {
|
||||
public var name:hl.Bytes;
|
||||
public var data:hl.Bytes;
|
||||
public var dataLen:Int;
|
||||
}
|
||||
|
||||
@:coreApi
|
||||
class Resource {
|
||||
static var content:hl.NativeArray<ResourceContent>;
|
||||
|
||||
public static function listNames():Array<String> {
|
||||
return [for (x in content) @:privateAccess String.fromUCS2(x.name)];
|
||||
}
|
||||
|
||||
public static function getString(name:String):String {
|
||||
for (x in content)
|
||||
if (x.name.compare(0, @:privateAccess name.bytes, 0, (name.length + 1) << 1) == 0)
|
||||
return @:privateAccess String.fromUTF8(x.data);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getBytes(name:String):haxe.io.Bytes {
|
||||
for (x in content)
|
||||
if (x.name.compare(0, @:privateAccess name.bytes, 0, (name.length + 1) << 1) == 0)
|
||||
return @:privateAccess new haxe.io.Bytes(x.data, x.dataLen);
|
||||
return null;
|
||||
}
|
||||
|
||||
static function __init__():Void {
|
||||
content = untyped $resources();
|
||||
}
|
||||
}
|
37
Kha/Tools/macos/std/hl/_std/haxe/crypto/Md5.hx
Normal file
37
Kha/Tools/macos/std/hl/_std/haxe/crypto/Md5.hx
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.crypto;
|
||||
|
||||
class Md5 {
|
||||
public static function encode(s:String):String {
|
||||
var out = haxe.io.Bytes.alloc(16);
|
||||
@:privateAccess hl.Format.digest(out.b, s.bytes, s.length, 256);
|
||||
return out.toHex();
|
||||
}
|
||||
|
||||
public static function make(b:haxe.io.Bytes):haxe.io.Bytes {
|
||||
var out = haxe.io.Bytes.alloc(16);
|
||||
@:privateAccess hl.Format.digest(out.b, b.b, b.length, 0);
|
||||
return out;
|
||||
}
|
||||
}
|
37
Kha/Tools/macos/std/hl/_std/haxe/crypto/Sha1.hx
Normal file
37
Kha/Tools/macos/std/hl/_std/haxe/crypto/Sha1.hx
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.crypto;
|
||||
|
||||
class Sha1 {
|
||||
public static function encode(s:String):String {
|
||||
var out = haxe.io.Bytes.alloc(20);
|
||||
@:privateAccess hl.Format.digest(out.b, s.bytes, s.length, 256 | 1);
|
||||
return out.toHex();
|
||||
}
|
||||
|
||||
public static function make(b:haxe.io.Bytes):haxe.io.Bytes {
|
||||
var out = haxe.io.Bytes.alloc(20);
|
||||
@:privateAccess hl.Format.digest(out.b, b.b, b.length, 1);
|
||||
return out;
|
||||
}
|
||||
}
|
91
Kha/Tools/macos/std/hl/_std/haxe/ds/IntMap.hx
Normal file
91
Kha/Tools/macos/std/hl/_std/haxe/ds/IntMap.hx
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.ds;
|
||||
|
||||
@:coreApi
|
||||
class IntMap<T> implements haxe.Constraints.IMap<Int, T> {
|
||||
var h:hl.types.IntMap;
|
||||
|
||||
public function new():Void {
|
||||
h = new hl.types.IntMap();
|
||||
}
|
||||
|
||||
public function set(key:Int, value:T):Void {
|
||||
@:privateAccess h.set(key, value);
|
||||
}
|
||||
|
||||
public function get(key:Int):Null<T> {
|
||||
return @:privateAccess h.get(key);
|
||||
}
|
||||
|
||||
public function exists(key:Int):Bool {
|
||||
return @:privateAccess h.exists(key);
|
||||
}
|
||||
|
||||
public function remove(key:Int):Bool {
|
||||
return @:privateAccess h.remove(key);
|
||||
}
|
||||
|
||||
public function keys():Iterator<Int> {
|
||||
return new hl.NativeArray.NativeArrayIterator<Int>(h.keysArray());
|
||||
}
|
||||
|
||||
public function iterator():Iterator<T> {
|
||||
return h.iterator();
|
||||
}
|
||||
|
||||
@:runtime public inline function keyValueIterator():KeyValueIterator<Int, T> {
|
||||
return new haxe.iterators.MapKeyValueIterator(this);
|
||||
}
|
||||
|
||||
public function copy():IntMap<T> {
|
||||
var copied = new IntMap();
|
||||
for (key in keys())
|
||||
copied.set(key, get(key));
|
||||
return copied;
|
||||
}
|
||||
|
||||
public function toString():String {
|
||||
var s = new StringBuf();
|
||||
var keys = h.keysArray();
|
||||
var values = h.valuesArray();
|
||||
s.addChar('{'.code);
|
||||
for (i in 0...keys.length) {
|
||||
if (i > 0)
|
||||
s.add(", ");
|
||||
s.add(keys[i]);
|
||||
s.add(" => ");
|
||||
s.add(values[i]);
|
||||
}
|
||||
s.addChar('}'.code);
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
public function clear():Void {
|
||||
#if (hl_ver >= version("1.11.0"))
|
||||
@:privateAccess h.clear();
|
||||
#else
|
||||
h = new hl.types.IntMap();
|
||||
#end
|
||||
}
|
||||
}
|
91
Kha/Tools/macos/std/hl/_std/haxe/ds/ObjectMap.hx
Normal file
91
Kha/Tools/macos/std/hl/_std/haxe/ds/ObjectMap.hx
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.ds;
|
||||
|
||||
@:coreApi
|
||||
class ObjectMap<K:{}, T> implements haxe.Constraints.IMap<K, T> {
|
||||
var h:hl.types.ObjectMap;
|
||||
|
||||
public function new():Void {
|
||||
h = new hl.types.ObjectMap();
|
||||
}
|
||||
|
||||
public function set(key:K, value:T):Void {
|
||||
@:privateAccess h.set(key, value);
|
||||
}
|
||||
|
||||
public function get(key:K):Null<T> {
|
||||
return @:privateAccess h.get(key);
|
||||
}
|
||||
|
||||
public function exists(key:K):Bool {
|
||||
return @:privateAccess h.exists(key);
|
||||
}
|
||||
|
||||
public function remove(key:K):Bool {
|
||||
return @:privateAccess h.remove(key);
|
||||
}
|
||||
|
||||
public function keys():Iterator<K> {
|
||||
return new hl.NativeArray.NativeArrayIterator<K>(cast h.keysArray());
|
||||
}
|
||||
|
||||
public function iterator():Iterator<T> {
|
||||
return h.iterator();
|
||||
}
|
||||
|
||||
@:runtime public inline function keyValueIterator():KeyValueIterator<K, T> {
|
||||
return new haxe.iterators.MapKeyValueIterator(this);
|
||||
}
|
||||
|
||||
public function copy():ObjectMap<K, T> {
|
||||
var copied = new ObjectMap();
|
||||
for (key in keys())
|
||||
copied.set(key, get(key));
|
||||
return copied;
|
||||
}
|
||||
|
||||
public function toString():String {
|
||||
var s = new StringBuf();
|
||||
var keys = h.keysArray();
|
||||
var values = h.valuesArray();
|
||||
s.addChar('{'.code);
|
||||
for (i in 0...keys.length) {
|
||||
if (i > 0)
|
||||
s.add(", ");
|
||||
s.add(keys[i]);
|
||||
s.add(" => ");
|
||||
s.add(values[i]);
|
||||
}
|
||||
s.addChar('}'.code);
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
public function clear():Void {
|
||||
#if (hl_ver >= version("1.11.0"))
|
||||
@:privateAccess h.clear();
|
||||
#else
|
||||
h = new hl.types.ObjectMap();
|
||||
#end
|
||||
}
|
||||
}
|
119
Kha/Tools/macos/std/hl/_std/haxe/ds/StringMap.hx
Normal file
119
Kha/Tools/macos/std/hl/_std/haxe/ds/StringMap.hx
Normal file
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.ds;
|
||||
|
||||
private class StringMapKeysIterator {
|
||||
var arr:hl.NativeArray<hl.Bytes>;
|
||||
var pos:Int;
|
||||
var length:Int;
|
||||
|
||||
public inline function new(h:hl.types.BytesMap) {
|
||||
this.arr = h.keysArray();
|
||||
pos = 0;
|
||||
length = arr.length;
|
||||
}
|
||||
|
||||
public inline function hasNext() {
|
||||
return pos < length;
|
||||
}
|
||||
|
||||
public inline function next() @:privateAccess {
|
||||
var b = arr[pos++];
|
||||
return String.fromUCS2(b);
|
||||
}
|
||||
}
|
||||
|
||||
@:coreApi
|
||||
class StringMap<T> implements haxe.Constraints.IMap<String, T> {
|
||||
var h:hl.types.BytesMap;
|
||||
|
||||
public function new():Void {
|
||||
h = new hl.types.BytesMap();
|
||||
}
|
||||
|
||||
public function set(key:String, value:T):Void {
|
||||
@:privateAccess h.set(key.bytes, value);
|
||||
}
|
||||
|
||||
public function get(key:String):Null<T> {
|
||||
if (key == null)
|
||||
return null;
|
||||
return @:privateAccess h.get(key.bytes);
|
||||
}
|
||||
|
||||
public function exists(key:String):Bool {
|
||||
if (key == null)
|
||||
return false;
|
||||
return @:privateAccess h.exists(key.bytes);
|
||||
}
|
||||
|
||||
public function remove(key:String):Bool {
|
||||
if (key == null)
|
||||
return false;
|
||||
return @:privateAccess h.remove(key.bytes);
|
||||
}
|
||||
|
||||
public function keys():Iterator<String> {
|
||||
return new StringMapKeysIterator(h);
|
||||
}
|
||||
|
||||
public function iterator():Iterator<T> {
|
||||
return h.iterator();
|
||||
}
|
||||
|
||||
@:runtime public inline function keyValueIterator():KeyValueIterator<String, T> {
|
||||
return new haxe.iterators.MapKeyValueIterator(this);
|
||||
}
|
||||
|
||||
public function copy():StringMap<T> {
|
||||
var copied = new StringMap();
|
||||
for (key in keys())
|
||||
copied.set(key, get(key));
|
||||
return copied;
|
||||
}
|
||||
|
||||
public function toString():String {
|
||||
var s = new StringBuf();
|
||||
var keys = h.keysArray();
|
||||
var values = h.valuesArray();
|
||||
s.addChar('{'.code);
|
||||
for (i in 0...keys.length) {
|
||||
if (i > 0)
|
||||
s.add(", ");
|
||||
var k = keys[i];
|
||||
@:privateAccess s.__add(k, 0, (@:privateAccess k.ucs2Length(0)) << 1);
|
||||
s.add(" => ");
|
||||
s.add(values[i]);
|
||||
}
|
||||
s.addChar('}'.code);
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
public function clear():Void {
|
||||
#if (hl_ver >= version("1.11.0"))
|
||||
@:privateAccess h.clear();
|
||||
#else
|
||||
h = new hl.types.BytesMap();
|
||||
#end
|
||||
}
|
||||
}
|
90
Kha/Tools/macos/std/hl/_std/haxe/ds/Vector.hx
Normal file
90
Kha/Tools/macos/std/hl/_std/haxe/ds/Vector.hx
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.ds;
|
||||
|
||||
private typedef VectorData<T> = Array<T>
|
||||
|
||||
@:coreApi
|
||||
abstract Vector<T>(VectorData<T>) {
|
||||
public inline function new(length:Int) {
|
||||
this = [];
|
||||
if (length > 0)
|
||||
this[length - 1] = cast null;
|
||||
}
|
||||
|
||||
@:op([]) public inline function get(index:Int):T {
|
||||
return this[index];
|
||||
}
|
||||
|
||||
@:op([]) public inline function set(index:Int, val:T):T {
|
||||
return this[index] = val;
|
||||
}
|
||||
|
||||
public var length(get, never):Int;
|
||||
|
||||
inline function get_length():Int {
|
||||
return this.length;
|
||||
}
|
||||
|
||||
public static inline function blit<T>(src:Vector<T>, srcPos:Int, dest:Vector<T>, destPos:Int, len:Int):Void {
|
||||
(cast dest : hl.types.ArrayBase.ArrayAccess).blit(destPos, (cast src : hl.types.ArrayBase.ArrayAccess), srcPos, len);
|
||||
}
|
||||
|
||||
public inline function toArray():Array<T> {
|
||||
return this.copy();
|
||||
}
|
||||
|
||||
public inline function toData():VectorData<T>
|
||||
return this;
|
||||
|
||||
static public inline function fromData<T>(data:VectorData<T>):Vector<T>
|
||||
return cast data;
|
||||
|
||||
static public inline function fromArrayCopy<T>(array:Array<T>):Vector<T> {
|
||||
return cast array.copy();
|
||||
}
|
||||
|
||||
public inline function copy<T>():Vector<T> {
|
||||
return cast this.copy();
|
||||
}
|
||||
|
||||
public inline function join<T>(sep:String):String {
|
||||
return this.join(sep);
|
||||
}
|
||||
|
||||
public inline function sort(f:T->T->Int):Void {
|
||||
this.sort(f);
|
||||
}
|
||||
|
||||
public inline function map<S>(f:T->S):Vector<S> {
|
||||
var length = length;
|
||||
var r = new Vector<S>(length);
|
||||
var i = 0;
|
||||
var len = length;
|
||||
for (i in 0...len) {
|
||||
var v = f(get(i));
|
||||
r.set(i, v);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
}
|
253
Kha/Tools/macos/std/hl/_std/haxe/io/Bytes.hx
Normal file
253
Kha/Tools/macos/std/hl/_std/haxe/io/Bytes.hx
Normal file
@ -0,0 +1,253 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.io;
|
||||
|
||||
@:coreApi
|
||||
class Bytes {
|
||||
public var length(default, null):Int;
|
||||
|
||||
var b:hl.Bytes;
|
||||
|
||||
function new(b:hl.Bytes, length:Int):Void {
|
||||
this.b = b;
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
inline function out(pos:Int):Bool {
|
||||
return (pos : UInt) >= (length : UInt);
|
||||
}
|
||||
|
||||
inline function outRange(pos:Int, len:Int):Bool {
|
||||
return pos < 0 || len < 0 || ((pos + len) : UInt) > (length : UInt);
|
||||
}
|
||||
|
||||
public function get(pos:Int):Int {
|
||||
return if (out(pos)) 0 else b[pos];
|
||||
}
|
||||
|
||||
public function set(pos:Int, v:Int):Void {
|
||||
if (out(pos))
|
||||
throw Error.OutsideBounds;
|
||||
b[pos] = v;
|
||||
}
|
||||
|
||||
public function blit(pos:Int, src:Bytes, srcpos:Int, len:Int):Void {
|
||||
if (outRange(pos, len) || src.outRange(srcpos, len))
|
||||
throw Error.OutsideBounds;
|
||||
b.blit(pos, src.b, srcpos, len);
|
||||
}
|
||||
|
||||
public function fill(pos:Int, len:Int, value:Int):Void {
|
||||
if (outRange(pos, len))
|
||||
throw Error.OutsideBounds;
|
||||
b.fill(pos, len, value);
|
||||
}
|
||||
|
||||
public function sub(pos:Int, len:Int):Bytes {
|
||||
if (outRange(pos, len))
|
||||
throw Error.OutsideBounds;
|
||||
return new Bytes(b.sub(pos, len), len);
|
||||
}
|
||||
|
||||
public function compare(other:Bytes):Int {
|
||||
var len = length < other.length ? length : other.length;
|
||||
var r = b.compare(0, other.b, 0, len);
|
||||
if (r == 0)
|
||||
r = length - other.length;
|
||||
return r;
|
||||
}
|
||||
|
||||
#if hl_check_align
|
||||
static var alignBuffer:hl.Bytes = new hl.Bytes(8);
|
||||
#end
|
||||
|
||||
public function getDouble(pos:Int):Float {
|
||||
if (out(pos + 7))
|
||||
return 0.;
|
||||
#if hl_check_align
|
||||
return if (pos & 3 == 0) b.getF64(pos) else {
|
||||
alignBuffer.blit(0, b, pos, 8);
|
||||
alignBuffer.getF64(0);
|
||||
}
|
||||
#else
|
||||
return b.getF64(pos);
|
||||
#end
|
||||
}
|
||||
|
||||
public function getFloat(pos:Int):Float {
|
||||
if (out(pos + 3))
|
||||
return 0.;
|
||||
#if hl_check_align
|
||||
return if (pos & 3 == 0) b.getF32(pos) else {
|
||||
alignBuffer.blit(0, b, pos, 4);
|
||||
alignBuffer.getF32(0);
|
||||
}
|
||||
#else
|
||||
return b.getF32(pos);
|
||||
#end
|
||||
}
|
||||
|
||||
public function setDouble(pos:Int, v:Float):Void {
|
||||
if (out(pos + 7))
|
||||
throw Error.OutsideBounds;
|
||||
#if hl_check_align
|
||||
if (pos & 7 == 0)
|
||||
b.setF64(pos, v);
|
||||
else {
|
||||
alignBuffer.setF64(0, v);
|
||||
b.blit(pos, alignBuffer, 0, 8);
|
||||
}
|
||||
#else
|
||||
b.setF64(pos, v);
|
||||
#end
|
||||
}
|
||||
|
||||
public function setFloat(pos:Int, v:Float):Void {
|
||||
if (out(pos + 3))
|
||||
throw Error.OutsideBounds;
|
||||
#if hl_check_align
|
||||
if (pos & 3 == 0)
|
||||
b.setF32(pos, v);
|
||||
else {
|
||||
alignBuffer.setF32(0, v);
|
||||
b.blit(pos, alignBuffer, 0, 4);
|
||||
}
|
||||
#else
|
||||
b.setF32(pos, v);
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function getUInt16(pos:Int):Int {
|
||||
return if (out(pos + 1)) 0 else b.getUI16(pos);
|
||||
}
|
||||
|
||||
public inline function setUInt16(pos:Int, v:Int):Void {
|
||||
if (out(pos + 1))
|
||||
throw Error.OutsideBounds;
|
||||
b.setUI16(pos, v);
|
||||
}
|
||||
|
||||
public function getInt32(pos:Int):Int {
|
||||
return if (out(pos + 3)) 0 else b.getI32(pos);
|
||||
}
|
||||
|
||||
public function getInt64(pos:Int):haxe.Int64 {
|
||||
if (out(pos + 7))
|
||||
return haxe.Int64.ofInt(0);
|
||||
return haxe.Int64.make(b.getI32(pos + 4), b.getI32(pos));
|
||||
}
|
||||
|
||||
public function setInt32(pos:Int, v:Int):Void {
|
||||
if (out(pos + 3))
|
||||
throw Error.OutsideBounds;
|
||||
b.setI32(pos, v);
|
||||
}
|
||||
|
||||
public inline function setInt64(pos:Int, v:haxe.Int64):Void {
|
||||
setInt32(pos + 4, v.high);
|
||||
setInt32(pos, v.low);
|
||||
}
|
||||
|
||||
public function getString(pos:Int, len:Int, ?encoding:Encoding):String {
|
||||
if (outRange(pos, len))
|
||||
throw Error.OutsideBounds;
|
||||
|
||||
var b = new hl.Bytes(len + 2);
|
||||
b.blit(0, this.b, pos, len);
|
||||
b[len] = 0;
|
||||
b[len + 1] = 0;
|
||||
return @:privateAccess (encoding == RawNative ? String.fromUCS2(b) : String.fromUTF8(b));
|
||||
}
|
||||
|
||||
@:deprecated("readString is deprecated, use getString instead")
|
||||
@:noCompletion
|
||||
public inline function readString(pos:Int, len:Int):String {
|
||||
return getString(pos, len);
|
||||
}
|
||||
|
||||
public function toString():String {
|
||||
return getString(0, length);
|
||||
}
|
||||
|
||||
public function toHex():String {
|
||||
var s = new StringBuf();
|
||||
var chars = [];
|
||||
var str = "0123456789abcdef";
|
||||
for (i in 0...str.length)
|
||||
chars.push(str.charCodeAt(i));
|
||||
for (i in 0...length) {
|
||||
var c = get(i);
|
||||
s.addChar(chars[c >> 4]);
|
||||
s.addChar(chars[c & 15]);
|
||||
}
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
public inline function getData():BytesData {
|
||||
return new haxe.io.BytesData(b, length);
|
||||
}
|
||||
|
||||
public static function alloc(length:Int):Bytes {
|
||||
var b = new hl.Bytes(length);
|
||||
b.fill(0, length, 0);
|
||||
return new Bytes(b, length);
|
||||
}
|
||||
|
||||
public static function ofString(s:String, ?encoding:Encoding):Bytes@:privateAccess {
|
||||
if (encoding == null)
|
||||
encoding = UTF8;
|
||||
return switch (encoding) {
|
||||
case RawNative:
|
||||
return new Bytes(s.bytes.sub(0, s.length << 1), s.length << 1);
|
||||
case UTF8:
|
||||
var size = 0;
|
||||
var b = s.bytes.utf16ToUtf8(s.length, size);
|
||||
return new Bytes(b, size);
|
||||
}
|
||||
}
|
||||
|
||||
public static function ofData(b:BytesData):Bytes {
|
||||
return new Bytes(b.bytes, b.length);
|
||||
}
|
||||
|
||||
public static function ofHex(s:String):Bytes {
|
||||
var len = s.length;
|
||||
if ((len & 1) != 0)
|
||||
throw "Not a hex string (odd number of digits)";
|
||||
var l = len >> 1;
|
||||
var b = new hl.Bytes(l);
|
||||
for (i in 0...l) {
|
||||
var high = s.charCodeAt(i * 2);
|
||||
var low = s.charCodeAt(i * 2 + 1);
|
||||
high = (high & 0xf) + ((high & 0x40) >> 6) * 9;
|
||||
low = (low & 0xf) + ((low & 0x40) >> 6) * 9;
|
||||
b.setUI8(i, ((high << 4) | low) & 0xff);
|
||||
}
|
||||
|
||||
return new Bytes(b, l);
|
||||
}
|
||||
|
||||
public inline static function fastGet(b:BytesData, pos:Int):Int {
|
||||
return b[pos];
|
||||
}
|
||||
}
|
131
Kha/Tools/macos/std/hl/_std/haxe/io/BytesBuffer.hx
Normal file
131
Kha/Tools/macos/std/hl/_std/haxe/io/BytesBuffer.hx
Normal file
@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.io;
|
||||
|
||||
@:coreApi
|
||||
class BytesBuffer {
|
||||
var b:hl.Bytes;
|
||||
var pos:Int;
|
||||
var size:Int;
|
||||
|
||||
public var length(get, never):Int;
|
||||
|
||||
public function new() {
|
||||
pos = 0;
|
||||
size = 16; // ensure increment of 8
|
||||
b = new hl.Bytes(size);
|
||||
}
|
||||
|
||||
inline function get_length():Int {
|
||||
return pos;
|
||||
}
|
||||
|
||||
public inline function addByte(byte:Int):Void {
|
||||
if (pos == size)
|
||||
__expand(0);
|
||||
b[pos++] = byte;
|
||||
}
|
||||
|
||||
function __expand(req:Int):Void {
|
||||
var nsize = (size * 3) >> 1;
|
||||
if (nsize < req)
|
||||
nsize = req;
|
||||
var b2 = new hl.Bytes(nsize);
|
||||
b2.blit(0, b, 0, pos);
|
||||
b = b2;
|
||||
size = nsize;
|
||||
}
|
||||
|
||||
function __add(b:hl.Bytes, bpos:Int, blen:Int):Void {
|
||||
if (pos + blen > size)
|
||||
__expand(pos + blen);
|
||||
this.b.blit(pos, b, bpos, blen);
|
||||
pos += blen;
|
||||
}
|
||||
|
||||
public inline function add(src:Bytes):Void {
|
||||
__add(@:privateAccess src.b, 0, src.length);
|
||||
}
|
||||
|
||||
public inline function addString(v:String, ?encoding:Encoding):Void {
|
||||
var len = 0;
|
||||
@:privateAccess (encoding == RawNative ? __add(v.bytes, 0, v.length << 1) : __add(v.bytes.utf16ToUtf8(0, len), 0, len));
|
||||
}
|
||||
|
||||
public inline function addInt32(v:Int):Void {
|
||||
if (pos + 4 > size)
|
||||
__expand(0);
|
||||
b.setI32(pos, v);
|
||||
pos += 4;
|
||||
}
|
||||
|
||||
public inline function addInt64(v:haxe.Int64):Void {
|
||||
if (pos + 8 > size)
|
||||
__expand(0);
|
||||
b.setI32(pos, v.low);
|
||||
b.setI32(pos + 4, v.high);
|
||||
pos += 8;
|
||||
}
|
||||
|
||||
public inline function addFloat(v:Float):Void {
|
||||
if (pos + 4 > size)
|
||||
__expand(0);
|
||||
#if hl_check_align
|
||||
if (pos & 3 == 0)
|
||||
b.setF32(pos, v);
|
||||
else @:privateAccess {
|
||||
haxe.io.Bytes.alignBuffer.setF32(0, v);
|
||||
b.blit(pos, haxe.io.Bytes.alignBuffer, 0, 4);
|
||||
}
|
||||
#else
|
||||
b.setF32(pos, v);
|
||||
#end
|
||||
pos += 4;
|
||||
}
|
||||
|
||||
public inline function addDouble(v:Float):Void {
|
||||
if (pos + 8 > size)
|
||||
__expand(0);
|
||||
#if hl_check_align
|
||||
if (pos & 7 == 0)
|
||||
b.setF64(pos, v);
|
||||
else @:privateAccess {
|
||||
haxe.io.Bytes.alignBuffer.setF64(0, v);
|
||||
b.blit(pos, haxe.io.Bytes.alignBuffer, 0, 8);
|
||||
}
|
||||
#else
|
||||
b.setF64(pos, v);
|
||||
#end
|
||||
pos += 8;
|
||||
}
|
||||
|
||||
public inline function addBytes(src:Bytes, pos:Int, len:Int):Void {
|
||||
if (pos < 0 || len < 0 || pos + len > src.length)
|
||||
throw Error.OutsideBounds;
|
||||
__add(@:privateAccess src.b, pos, len);
|
||||
}
|
||||
|
||||
public function getBytes():Bytes {
|
||||
return @:privateAccess new haxe.io.Bytes(b, pos);
|
||||
}
|
||||
}
|
55
Kha/Tools/macos/std/hl/_std/haxe/io/FPHelper.hx
Normal file
55
Kha/Tools/macos/std/hl/_std/haxe/io/FPHelper.hx
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.io;
|
||||
|
||||
class FPHelper {
|
||||
// note : this is not thread safe, use TLS when available
|
||||
static var i64tmp = Int64.ofInt(0);
|
||||
static var helper = new hl.Bytes(8);
|
||||
|
||||
public static function i32ToFloat(i:Int):Single {
|
||||
helper.setI32(0, i);
|
||||
return helper.getF32(0);
|
||||
}
|
||||
|
||||
public static function floatToI32(f:Single):Int {
|
||||
helper.setF32(0, f);
|
||||
return helper.getI32(0);
|
||||
}
|
||||
|
||||
public static function i64ToDouble(low:Int, high:Int):Float {
|
||||
helper.setI32(0, low);
|
||||
helper.setI32(4, high);
|
||||
return helper.getF64(0);
|
||||
}
|
||||
|
||||
public static function doubleToI64(v:Float):Int64 {
|
||||
helper.setF64(0, v);
|
||||
var i64 = i64tmp;
|
||||
@:privateAccess {
|
||||
i64.set_low(helper.getI32(0));
|
||||
i64.set_high(helper.getI32(4));
|
||||
}
|
||||
return i64;
|
||||
}
|
||||
}
|
75
Kha/Tools/macos/std/hl/_std/haxe/zip/Compress.hx
Normal file
75
Kha/Tools/macos/std/hl/_std/haxe/zip/Compress.hx
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.zip;
|
||||
|
||||
private typedef Deflater = hl.Abstract<"fmt_zip">;
|
||||
|
||||
@:coreApi @:hlNative("fmt")
|
||||
class Compress {
|
||||
var s:Deflater;
|
||||
|
||||
public function new(level:Int):Void {
|
||||
s = deflate_init(level);
|
||||
}
|
||||
|
||||
public function execute(src:haxe.io.Bytes, srcPos:Int, dst:haxe.io.Bytes, dstPos:Int):{done:Bool, read:Int, write:Int} {
|
||||
var read = 0, write = 0;
|
||||
var done = deflate_buffer(s, src.getData(), srcPos, src.length, dst.getData(), dstPos, dst.length, read, write);
|
||||
return {done: done, read: read, write: write};
|
||||
}
|
||||
|
||||
public function setFlushMode(f:FlushMode):Void {
|
||||
@:privateAccess Uncompress.zip_flush_mode(cast s, f.getIndex());
|
||||
}
|
||||
|
||||
public function close():Void {
|
||||
@:privateAccess Uncompress.zip_end(cast s);
|
||||
}
|
||||
|
||||
public static function run(s:haxe.io.Bytes, level:Int):haxe.io.Bytes {
|
||||
var c = new Compress(level);
|
||||
c.setFlushMode(FlushMode.FINISH);
|
||||
var out = haxe.io.Bytes.alloc(deflate_bound(c.s, s.length));
|
||||
var r = c.execute(s, 0, out, 0);
|
||||
c.close();
|
||||
if (!r.done || r.read != s.length)
|
||||
throw "Compression failed";
|
||||
if (r.write < out.length * 0.66)
|
||||
return out.sub(0, r.write);
|
||||
@:privateAccess out.length = r.write;
|
||||
return out;
|
||||
}
|
||||
|
||||
static function deflate_init(level:Int):Deflater {
|
||||
return null;
|
||||
}
|
||||
|
||||
static function deflate_buffer(i:Deflater, bytes:hl.Bytes, bytesPos:Int, bytesLen:Int, dst:hl.Bytes, dstPos:Int, dstLen:Int, read:hl.Ref<Int>,
|
||||
write:hl.Ref<Int>):Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
static function deflate_bound(i:Deflater, length:Int):Int {
|
||||
return 0;
|
||||
}
|
||||
}
|
80
Kha/Tools/macos/std/hl/_std/haxe/zip/Uncompress.hx
Normal file
80
Kha/Tools/macos/std/hl/_std/haxe/zip/Uncompress.hx
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.zip;
|
||||
|
||||
private typedef Inflater = hl.Abstract<"fmt_zip">;
|
||||
|
||||
@:coreApi @:hlNative("fmt")
|
||||
class Uncompress {
|
||||
var s:Inflater;
|
||||
|
||||
public function new(?windowBits:Int):Void {
|
||||
s = inflate_init(windowBits);
|
||||
}
|
||||
|
||||
public function execute(src:haxe.io.Bytes, srcPos:Int, dst:haxe.io.Bytes, dstPos:Int):{done:Bool, read:Int, write:Int} {
|
||||
var read = 0, write = 0;
|
||||
var done = inflate_buffer(s, src.getData(), srcPos, src.length, dst.getData(), dstPos, dst.length, read, write);
|
||||
return {done: done, read: read, write: write};
|
||||
}
|
||||
|
||||
public function setFlushMode(f:FlushMode):Void {
|
||||
zip_flush_mode(s, f.getIndex());
|
||||
}
|
||||
|
||||
public function close():Void {
|
||||
zip_end(s);
|
||||
}
|
||||
|
||||
public static function run(src:haxe.io.Bytes, ?bufsize:Int):haxe.io.Bytes {
|
||||
var u = new Uncompress(null);
|
||||
if (bufsize == null)
|
||||
bufsize = 1 << 16; // 64K
|
||||
var tmp = haxe.io.Bytes.alloc(bufsize);
|
||||
var b = new haxe.io.BytesBuffer();
|
||||
var pos = 0;
|
||||
u.setFlushMode(FlushMode.SYNC);
|
||||
while (true) {
|
||||
var r = u.execute(src, pos, tmp, 0);
|
||||
b.addBytes(tmp, 0, r.write);
|
||||
pos += r.read;
|
||||
if (r.done)
|
||||
break;
|
||||
}
|
||||
u.close();
|
||||
return b.getBytes();
|
||||
}
|
||||
|
||||
static function inflate_init(bits:Int):Inflater {
|
||||
return null;
|
||||
}
|
||||
|
||||
static function inflate_buffer(i:Inflater, bytes:hl.Bytes, bytesPos:Int, bytesLen:Int, dst:hl.Bytes, dstPos:Int, dstLen:Int, read:hl.Ref<Int>,
|
||||
write:hl.Ref<Int>):Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
static function zip_end(i:Inflater):Void {}
|
||||
|
||||
static function zip_flush_mode(i:Inflater, flush:Int):Void {}
|
||||
}
|
147
Kha/Tools/macos/std/hl/_std/sys/FileSystem.hx
Normal file
147
Kha/Tools/macos/std/hl/_std/sys/FileSystem.hx
Normal file
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys;
|
||||
|
||||
@:coreApi
|
||||
@:access(Sys)
|
||||
class FileSystem {
|
||||
public static function exists(path:String):Bool {
|
||||
return sys_exists(Sys.getPath(makeCompatiblePath(path)));
|
||||
}
|
||||
|
||||
public static function rename(path:String, newPath:String):Void {
|
||||
if (!sys_rename(Sys.getPath(path), Sys.getPath(newPath)))
|
||||
throw new Sys.SysError("Failed to rename " + path + " to " + newPath);
|
||||
}
|
||||
|
||||
public static function stat(path:String):FileStat {
|
||||
var values = sys_stat(Sys.getPath(makeCompatiblePath(path)));
|
||||
if (values == null)
|
||||
throw new Sys.SysError("Failed to stat " + path);
|
||||
return {
|
||||
gid: values[0],
|
||||
uid: values[1],
|
||||
atime: @:privateAccess Date.fromInt(values[2]),
|
||||
mtime: @:privateAccess Date.fromInt(values[3]),
|
||||
ctime: @:privateAccess Date.fromInt(values[4]),
|
||||
size: values[5],
|
||||
dev: values[6],
|
||||
ino: values[7],
|
||||
nlink: values[8],
|
||||
rdev: values[9],
|
||||
mode: values[10],
|
||||
};
|
||||
}
|
||||
|
||||
public static function fullPath(relPath:String):String {
|
||||
return Sys.makePath(sys_full_path(Sys.getPath(relPath)));
|
||||
}
|
||||
|
||||
public static function absolutePath(relPath:String):String {
|
||||
if (haxe.io.Path.isAbsolute(relPath))
|
||||
return relPath;
|
||||
return haxe.io.Path.join([Sys.getCwd(), relPath]);
|
||||
}
|
||||
|
||||
public static function isDirectory(path:String):Bool {
|
||||
return sys_is_dir(Sys.getPath(makeCompatiblePath(path)));
|
||||
}
|
||||
|
||||
public static function createDirectory(path:String):Void {
|
||||
var path = haxe.io.Path.addTrailingSlash(path);
|
||||
var _p = null;
|
||||
var parts = [];
|
||||
while (path != (_p = haxe.io.Path.directory(path))) {
|
||||
parts.unshift(path);
|
||||
path = _p;
|
||||
}
|
||||
for (part in parts) {
|
||||
if (part.charCodeAt(part.length - 1) != ":".code && !exists(part))
|
||||
if (!sys_create_dir(Sys.getPath(part), 493))
|
||||
throw new Sys.SysError("Failed to create directory " + part);
|
||||
}
|
||||
}
|
||||
|
||||
public static function deleteFile(path:String):Void {
|
||||
if (!sys_delete(Sys.getPath(path)))
|
||||
throw new Sys.SysError("Can't delete file " + path);
|
||||
}
|
||||
|
||||
public static function deleteDirectory(path:String):Void {
|
||||
if (!sys_remove_dir(Sys.getPath(path)))
|
||||
throw new Sys.SysError("Can't delete directory " + path);
|
||||
}
|
||||
|
||||
public static function readDirectory(path:String):Array<String> {
|
||||
var content = sys_read_dir(Sys.getPath(path));
|
||||
if (content == null)
|
||||
throw new Sys.SysError("Failed to read directory " + path);
|
||||
return [for (c in content) Sys.makePath(c)];
|
||||
}
|
||||
|
||||
private static inline function makeCompatiblePath(path:String):String {
|
||||
return if (path.charCodeAt(1) == ":".code && path.length <= 3) {
|
||||
haxe.io.Path.addTrailingSlash(path);
|
||||
} else if (path == "/") {
|
||||
"/";
|
||||
} else {
|
||||
haxe.io.Path.removeTrailingSlashes(path);
|
||||
}
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_read_dir") static function sys_read_dir(path:hl.Bytes):hl.NativeArray<hl.Bytes> {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_create_dir") static function sys_create_dir(path:hl.Bytes, rights:Int):Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_is_dir") static function sys_is_dir(path:hl.Bytes):Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_stat") static function sys_stat(path:hl.Bytes):hl.NativeArray<Int> {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_rename") static function sys_rename(path:hl.Bytes, to:hl.Bytes):Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_delete") static function sys_delete(path:hl.Bytes):Bool {
|
||||
return true;
|
||||
};
|
||||
|
||||
@:hlNative("std", "sys_full_path") static function sys_full_path(path:hl.Bytes):hl.Bytes {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_remove_dir") static function sys_remove_dir(path:hl.Bytes):Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
@:hlNative("std", "sys_exists") static function sys_exists(path:hl.Bytes):Bool {
|
||||
return true;
|
||||
}
|
||||
}
|
36
Kha/Tools/macos/std/hl/_std/sys/db/Connection.hx
Normal file
36
Kha/Tools/macos/std/hl/_std/sys/db/Connection.hx
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.db;
|
||||
|
||||
interface Connection {
|
||||
function request(s:String):ResultSet;
|
||||
function close():Void;
|
||||
function escape(s:String):String;
|
||||
function quote(s:String):String;
|
||||
function addValue(s:StringBuf, v:Dynamic):Void;
|
||||
function lastInsertId():Int;
|
||||
function dbName():String;
|
||||
function startTransaction():Void;
|
||||
function commit():Void;
|
||||
function rollback():Void;
|
||||
}
|
250
Kha/Tools/macos/std/hl/_std/sys/db/Mysql.hx
Normal file
250
Kha/Tools/macos/std/hl/_std/sys/db/Mysql.hx
Normal file
@ -0,0 +1,250 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.db;
|
||||
|
||||
private class MysqlParams {
|
||||
public var host:hl.Bytes;
|
||||
public var user:hl.Bytes;
|
||||
public var pass:hl.Bytes;
|
||||
public var socket:hl.Bytes;
|
||||
public var port:Int;
|
||||
|
||||
public function new() {}
|
||||
}
|
||||
|
||||
private typedef ConnectionHandler = hl.Abstract<"mysql_cnx">;
|
||||
private typedef ResultHandler = hl.Abstract<"mysql_result">;
|
||||
|
||||
@:hlNative("mysql")
|
||||
private class MysqlResultSet implements sys.db.ResultSet {
|
||||
public var length(get, null):Int;
|
||||
public var nfields(get, null):Int;
|
||||
|
||||
private var r:ResultHandler;
|
||||
private var cache:Dynamic;
|
||||
|
||||
function new(r) {
|
||||
this.r = r;
|
||||
}
|
||||
|
||||
private function get_length() {
|
||||
return result_get_length(r);
|
||||
}
|
||||
|
||||
private function get_nfields() {
|
||||
return result_get_nfields(r);
|
||||
}
|
||||
|
||||
public function hasNext() {
|
||||
if (cache == null)
|
||||
cache = next();
|
||||
return (cache != null);
|
||||
}
|
||||
|
||||
public function next():Dynamic {
|
||||
var c = cache;
|
||||
if (c != null) {
|
||||
cache = null;
|
||||
return c;
|
||||
}
|
||||
c = result_next(r);
|
||||
return c;
|
||||
}
|
||||
|
||||
public function results():List<Dynamic> {
|
||||
var l = new List();
|
||||
while (hasNext())
|
||||
l.add(next());
|
||||
return l;
|
||||
}
|
||||
|
||||
public function getResult(n:Int) {
|
||||
var v = result_get(r, n);
|
||||
if (v == null)
|
||||
return null;
|
||||
return @:privateAccess String.fromUTF8(v);
|
||||
}
|
||||
|
||||
public function getIntResult(n:Int):Int {
|
||||
return result_get_int(r, n);
|
||||
}
|
||||
|
||||
public function getFloatResult(n:Int):Float {
|
||||
return result_get_float(r, n);
|
||||
}
|
||||
|
||||
public function getFieldsNames():Array<String> {
|
||||
var a = result_get_fields_names(r);
|
||||
return [for (v in a) @:privateAccess String.fromUTF8(v)];
|
||||
}
|
||||
|
||||
static function result_get_length(r:ResultHandler):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static function result_get_nfields(r:ResultHandler):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static function result_next(r:ResultHandler):Dynamic {
|
||||
return null;
|
||||
}
|
||||
|
||||
static function result_get(r:ResultHandler, n:Int):hl.Bytes {
|
||||
return null;
|
||||
}
|
||||
|
||||
static function result_get_int(r:ResultHandler, n:Int):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static function result_get_float(r:ResultHandler, n:Int):Float {
|
||||
return 0.;
|
||||
}
|
||||
|
||||
static function result_get_fields_names(r:ResultHandler):hl.NativeArray<hl.Bytes> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@:hlNative("mysql")
|
||||
private class MysqlConnection implements Connection {
|
||||
var h:ConnectionHandler;
|
||||
|
||||
function new(h) {
|
||||
this.h = h;
|
||||
}
|
||||
|
||||
public function close() {
|
||||
if (h != null)
|
||||
close_wrap(h);
|
||||
h = null;
|
||||
}
|
||||
|
||||
public function request(s:String) @:privateAccess {
|
||||
var len = 0;
|
||||
var b = s.bytes.utf16ToUtf8(0, len);
|
||||
return new MysqlResultSet(request_wrap(h, b, len));
|
||||
}
|
||||
|
||||
public function escape(s:String) @:privateAccess {
|
||||
var len = 0;
|
||||
var utf = s.bytes.utf16ToUtf8(0, len);
|
||||
return String.fromUTF8(escape_wrap(h, utf, len));
|
||||
}
|
||||
|
||||
public function quote(s:String) {
|
||||
return "'" + escape(s) + "'";
|
||||
}
|
||||
|
||||
public function addValue(s:StringBuf, v:Dynamic) {
|
||||
if (v == null) {
|
||||
s.add(null);
|
||||
return;
|
||||
}
|
||||
var t = hl.Type.getDynamic(v).kind;
|
||||
if (t == HI32 || t == HF64)
|
||||
s.add(v);
|
||||
else if (t == HBool)
|
||||
s.addChar(if (v) "1".code else "0".code);
|
||||
else {
|
||||
s.addChar("'".code);
|
||||
s.add(escape(Std.string(v)));
|
||||
s.addChar("'".code);
|
||||
}
|
||||
}
|
||||
|
||||
public function lastInsertId() {
|
||||
return request("SELECT LAST_INSERT_ID()").getIntResult(0);
|
||||
}
|
||||
|
||||
public function dbName() {
|
||||
return "MySQL";
|
||||
}
|
||||
|
||||
public function startTransaction() {
|
||||
request("START TRANSACTION");
|
||||
}
|
||||
|
||||
public function commit() {
|
||||
request("COMMIT");
|
||||
}
|
||||
|
||||
public function rollback() {
|
||||
request("ROLLBACK");
|
||||
}
|
||||
|
||||
static function close_wrap(h:ConnectionHandler) {}
|
||||
|
||||
static function connect_wrap(p:MysqlParams):ConnectionHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
static function select_db_wrap(h:ConnectionHandler, db:hl.Bytes):Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
@:hlNative("mysql", "request")
|
||||
static function request_wrap(h:ConnectionHandler, rq:hl.Bytes, rqLen:Int):ResultHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("mysql", "escape")
|
||||
static function escape_wrap(h:ConnectionHandler, str:hl.Bytes, len:Int):hl.Bytes {
|
||||
return null;
|
||||
}
|
||||
|
||||
static function setConvFuns(fstring:Dynamic, fbytes:Dynamic, fdate:Dynamic, fjson:Dynamic) {};
|
||||
}
|
||||
|
||||
class Mysql {
|
||||
static var INIT_DONE = false;
|
||||
|
||||
public static function connect(params:{
|
||||
host:String,
|
||||
?port:Int,
|
||||
user:String,
|
||||
pass:String,
|
||||
?socket:String,
|
||||
?database:String
|
||||
}):sys.db.Connection@:privateAccess {
|
||||
if (!INIT_DONE) {
|
||||
INIT_DONE = true;
|
||||
MysqlConnection.setConvFuns(function(v:hl.Bytes) return @:privateAccess String.fromUTF8(v),
|
||||
function(v:hl.Bytes, len:Int) return new haxe.io.Bytes(v, len), function(t) return Date.fromTime(1000. * t),
|
||||
function(v:hl.Bytes) return haxe.Json.parse(@:privateAccess String.fromUTF8(v)));
|
||||
}
|
||||
var p = new MysqlParams();
|
||||
p.host = params.host == null ? null : params.host.toUtf8();
|
||||
p.user = params.user.toUtf8();
|
||||
p.pass = params.pass.toUtf8();
|
||||
p.socket = params.socket == null ? null : params.socket.toUtf8();
|
||||
p.port = params.port == null ? 3306 : params.port;
|
||||
var cnx = new MysqlConnection(MysqlConnection.connect_wrap(p));
|
||||
if (params.database != null && !MysqlConnection.select_db_wrap(cnx.h, params.database.toUtf8())) {
|
||||
cnx.close();
|
||||
throw "Failed to select database " + params.database;
|
||||
}
|
||||
return cnx;
|
||||
}
|
||||
}
|
36
Kha/Tools/macos/std/hl/_std/sys/db/ResultSet.hx
Normal file
36
Kha/Tools/macos/std/hl/_std/sys/db/ResultSet.hx
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.db;
|
||||
|
||||
interface ResultSet {
|
||||
var length(get, null):Int;
|
||||
var nfields(get, null):Int;
|
||||
|
||||
function hasNext():Bool;
|
||||
function next():Dynamic;
|
||||
function results():List<Dynamic>;
|
||||
function getResult(n:Int):String;
|
||||
function getIntResult(n:Int):Int;
|
||||
function getFloatResult(n:Int):Float;
|
||||
function getFieldsNames():Null<Array<String>>;
|
||||
}
|
283
Kha/Tools/macos/std/hl/_std/sys/db/Sqlite.hx
Normal file
283
Kha/Tools/macos/std/hl/_std/sys/db/Sqlite.hx
Normal file
@ -0,0 +1,283 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.db;
|
||||
|
||||
import haxe.crypto.BaseCode;
|
||||
|
||||
private typedef SqliteConnectionHandle = hl.Abstract<"sqlite_database">;
|
||||
private typedef SqliteResultHandle = hl.Abstract<"sqlite_result">;
|
||||
|
||||
@:hlNative("sqlite")
|
||||
private class SqliteLib {
|
||||
public static function connect(path:hl.Bytes):SqliteConnectionHandle {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function close(c:SqliteConnectionHandle):Void {}
|
||||
|
||||
public static function request(c:SqliteConnectionHandle, sql:hl.Bytes):SqliteResultHandle {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function last_id(c:SqliteConnectionHandle):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function result_next(c:SqliteResultHandle):hl.NativeArray<Dynamic> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function result_get(c:SqliteResultHandle, n:Int):Null<hl.Bytes> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function result_get_int(c:SqliteResultHandle, n:Int):Null<Int> {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function result_get_float(c:SqliteResultHandle, n:Int):Null<Float> {
|
||||
return .0;
|
||||
}
|
||||
|
||||
public static function result_get_length(c:SqliteResultHandle):Null<Int> {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function result_get_nfields(c:SqliteResultHandle):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function result_get_fields(c:SqliteResultHandle):hl.NativeArray<hl.Bytes> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@:access(Sys)
|
||||
@:access(String)
|
||||
private class SqliteConnection implements Connection {
|
||||
var c:SqliteConnectionHandle;
|
||||
|
||||
public function new(file:String) {
|
||||
c = SqliteLib.connect(file.bytes);
|
||||
}
|
||||
|
||||
public function close():Void {
|
||||
SqliteLib.close(c);
|
||||
}
|
||||
|
||||
public function request(s:String):ResultSet {
|
||||
try {
|
||||
var r:SqliteResultHandle = SqliteLib.request(c, s.bytes);
|
||||
|
||||
return new SqliteResultSet(r);
|
||||
} catch (e:String) {
|
||||
throw 'Error while executing $s ($e)';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function escape(s:String):String {
|
||||
return s.split("'").join("''");
|
||||
}
|
||||
|
||||
public function quote(s:String):String {
|
||||
if (s.indexOf("\000") >= 0)
|
||||
return "x'" + BaseCode.encode(s, "0123456789ABCDEF") + "'";
|
||||
|
||||
return "'" + s.split("'").join("''") + "'";
|
||||
}
|
||||
|
||||
public function addValue(s:StringBuf, v:Dynamic):Void {
|
||||
switch (Type.typeof(v)) {
|
||||
case TNull, TInt:
|
||||
s.add(v);
|
||||
case TBool:
|
||||
s.add(v ? 1 : 0);
|
||||
case TClass(haxe.io.Bytes):
|
||||
s.add("x'");
|
||||
s.add((v : haxe.io.Bytes).toHex());
|
||||
s.add("'");
|
||||
case _:
|
||||
s.add(quote(Std.string(v)));
|
||||
}
|
||||
}
|
||||
|
||||
public function lastInsertId():Int {
|
||||
return SqliteLib.last_id(c);
|
||||
}
|
||||
|
||||
public function dbName():String {
|
||||
return "SQLite";
|
||||
}
|
||||
|
||||
public function startTransaction():Void {
|
||||
request("BEGIN TRANSACTION");
|
||||
}
|
||||
|
||||
public function commit():Void {
|
||||
request("COMMIT");
|
||||
}
|
||||
|
||||
public function rollback():Void {
|
||||
request("ROLLBACK");
|
||||
}
|
||||
}
|
||||
|
||||
@:access(String)
|
||||
private class SqliteResultSet implements ResultSet {
|
||||
public var length(get, null):Int;
|
||||
public var nfields(get, null):Int;
|
||||
|
||||
var names:Array<String>;
|
||||
var cache:List<Dynamic>;
|
||||
|
||||
var r:SqliteResultHandle;
|
||||
|
||||
public function new(r:SqliteResultHandle) {
|
||||
cache = new List();
|
||||
this.r = r;
|
||||
hasNext(); // execute the request
|
||||
}
|
||||
|
||||
function get_length():Int {
|
||||
if (nfields != 0) {
|
||||
while (true) {
|
||||
var c = doNext();
|
||||
if (c == null)
|
||||
break;
|
||||
|
||||
cache.add(c);
|
||||
}
|
||||
|
||||
return cache.length;
|
||||
}
|
||||
|
||||
return SqliteLib.result_get_length(r);
|
||||
}
|
||||
|
||||
function get_nfields():Int {
|
||||
return SqliteLib.result_get_nfields(r);
|
||||
}
|
||||
|
||||
public function hasNext():Bool {
|
||||
var c = next();
|
||||
if (c == null)
|
||||
return false;
|
||||
|
||||
cache.push(c);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function next():Dynamic {
|
||||
var c = cache.pop();
|
||||
if (c != null)
|
||||
return c;
|
||||
|
||||
return doNext();
|
||||
}
|
||||
|
||||
private function doNext():Dynamic {
|
||||
var o:Dynamic = {};
|
||||
var a = SqliteLib.result_next(r);
|
||||
if (a == null)
|
||||
return null;
|
||||
|
||||
var names = getFieldsNames();
|
||||
var i = 0;
|
||||
var l = names.length;
|
||||
while (i < l) {
|
||||
var n:String = names[i];
|
||||
var v:Dynamic = a[i];
|
||||
switch (hl.Type.getDynamic(v).kind) {
|
||||
case hl.Type.TypeKind.HArray:
|
||||
var pair:hl.NativeArray<Dynamic> = v;
|
||||
var bytes:hl.Bytes = pair[0];
|
||||
var len:Int = pair[1];
|
||||
var data = new haxe.io.BytesData(bytes, len);
|
||||
Reflect.setField(o, n, haxe.io.Bytes.ofData(data));
|
||||
|
||||
case hl.Type.TypeKind.HBytes:
|
||||
Reflect.setField(o, n, String.fromUCS2(v));
|
||||
|
||||
default:
|
||||
Reflect.setField(o, n, v);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
public function results():List<Dynamic> {
|
||||
var l = new List();
|
||||
while (true) {
|
||||
var c = next();
|
||||
if (c == null)
|
||||
break;
|
||||
|
||||
l.add(c);
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
public function getResult(n:Int):String {
|
||||
var bytes = SqliteLib.result_get(r, n);
|
||||
if (bytes == null)
|
||||
return null;
|
||||
|
||||
return String.fromUCS2(bytes);
|
||||
}
|
||||
|
||||
public function getIntResult(n:Int):Int {
|
||||
return SqliteLib.result_get_int(r, n);
|
||||
}
|
||||
|
||||
public function getFloatResult(n:Int):Float {
|
||||
return SqliteLib.result_get_float(r, n);
|
||||
}
|
||||
|
||||
public function getFieldsNames():Array<String> {
|
||||
if (this.names != null)
|
||||
return this.names;
|
||||
|
||||
this.names = [];
|
||||
var names = SqliteLib.result_get_fields(r);
|
||||
var i = 0;
|
||||
var l = names.length;
|
||||
while (i < l) {
|
||||
var name = String.fromUCS2(names[i]);
|
||||
this.names.push(name);
|
||||
i++;
|
||||
}
|
||||
|
||||
return this.names;
|
||||
}
|
||||
}
|
||||
|
||||
@:coreApi class Sqlite {
|
||||
public static function open(file:String):Connection {
|
||||
return new SqliteConnection(file);
|
||||
}
|
||||
}
|
106
Kha/Tools/macos/std/hl/_std/sys/io/File.hx
Normal file
106
Kha/Tools/macos/std/hl/_std/sys/io/File.hx
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.io;
|
||||
|
||||
#if doc_gen
|
||||
enum FileHandle {}
|
||||
#else
|
||||
typedef FileHandle = hl.Abstract<"hl_fdesc">;
|
||||
#end
|
||||
|
||||
@:access(Sys)
|
||||
@:coreApi class File {
|
||||
public static function getContent(path:String):String {
|
||||
var bytes = file_contents(Sys.getPath(path), null);
|
||||
if (bytes == null)
|
||||
throw new Sys.SysError("Can't read " + path);
|
||||
return @:privateAccess String.fromUTF8(bytes);
|
||||
}
|
||||
|
||||
public static function getBytes(path:String):haxe.io.Bytes {
|
||||
var size = 0;
|
||||
var bytes = file_contents(Sys.getPath(path), size);
|
||||
if (bytes == null)
|
||||
throw new Sys.SysError("Can't read " + path);
|
||||
return @:privateAccess new haxe.io.Bytes(bytes, size);
|
||||
}
|
||||
|
||||
public static function saveContent(path:String, content:String):Void {
|
||||
var f = write(path);
|
||||
f.writeString(content);
|
||||
f.close();
|
||||
}
|
||||
|
||||
public static function saveBytes(path:String, bytes:haxe.io.Bytes):Void {
|
||||
var f = write(path);
|
||||
f.write(bytes);
|
||||
f.close();
|
||||
}
|
||||
|
||||
public static function read(path:String, binary:Bool = true):FileInput {
|
||||
var f = file_open(Sys.getPath(path), 0, binary);
|
||||
if (f == null)
|
||||
throw new Sys.SysError("Can't open " + path);
|
||||
return @:privateAccess new FileInput(f);
|
||||
}
|
||||
|
||||
public static function write(path:String, binary:Bool = true):FileOutput {
|
||||
var f = file_open(Sys.getPath(path), 1, binary);
|
||||
if (f == null)
|
||||
throw new Sys.SysError("Can't open " + path + " for writing");
|
||||
return @:privateAccess new FileOutput(f);
|
||||
}
|
||||
|
||||
public static function append(path:String, binary:Bool = true):FileOutput {
|
||||
var f = file_open(Sys.getPath(path), 2, binary);
|
||||
if (f == null)
|
||||
throw new Sys.SysError("Can't open " + path + " for append");
|
||||
return @:privateAccess new FileOutput(f);
|
||||
}
|
||||
|
||||
public static function update(path:String, binary:Bool = true):FileOutput {
|
||||
if (!FileSystem.exists(path)) {
|
||||
write(path).close();
|
||||
}
|
||||
var f = file_open(Sys.getPath(path), 3, binary);
|
||||
if (f == null)
|
||||
throw new Sys.SysError("Can't open " + path + " for update");
|
||||
return @:privateAccess new FileOutput(f);
|
||||
}
|
||||
|
||||
public static function copy(srcPath:String, dstPath:String):Void {
|
||||
var s = read(srcPath, true);
|
||||
var d = write(dstPath, true);
|
||||
d.writeInput(s);
|
||||
s.close();
|
||||
d.close();
|
||||
}
|
||||
|
||||
@:hlNative("std", "file_open") static function file_open(path:hl.Bytes, mode:Int, binary:Bool):FileHandle {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "file_contents") static function file_contents(path:hl.Bytes, size:hl.Ref<Int>):hl.Bytes {
|
||||
return null;
|
||||
}
|
||||
}
|
97
Kha/Tools/macos/std/hl/_std/sys/io/FileInput.hx
Normal file
97
Kha/Tools/macos/std/hl/_std/sys/io/FileInput.hx
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.io;
|
||||
|
||||
import sys.io.File;
|
||||
|
||||
@:coreApi class FileInput extends haxe.io.Input {
|
||||
private var __f:FileHandle;
|
||||
|
||||
function new(f:FileHandle):Void {
|
||||
__f = f;
|
||||
}
|
||||
|
||||
public override function readByte():Int {
|
||||
var c = file_read_char(__f);
|
||||
if (c < 0)
|
||||
throw new haxe.io.Eof();
|
||||
return c;
|
||||
}
|
||||
|
||||
public override function readBytes(s:haxe.io.Bytes, p:Int, l:Int):Int {
|
||||
if (p < 0 || l < 0 || p + l > s.length)
|
||||
throw haxe.io.Error.OutsideBounds;
|
||||
var v = file_read(__f, s.getData(), p, l);
|
||||
if (v <= 0)
|
||||
throw new haxe.io.Eof();
|
||||
return v;
|
||||
}
|
||||
|
||||
public override function close():Void {
|
||||
super.close();
|
||||
file_close(__f);
|
||||
__f = null;
|
||||
}
|
||||
|
||||
public function seek(p:Int, pos:FileSeek):Void {
|
||||
if (!file_seek(__f, p, switch (pos) {
|
||||
case SeekBegin: 0;
|
||||
case SeekCur: 1;
|
||||
case SeekEnd: 2;
|
||||
}))
|
||||
throw haxe.io.Error.Custom("seek() failure");
|
||||
}
|
||||
|
||||
public function tell():Int {
|
||||
var p = file_tell(__f);
|
||||
if (p < 0)
|
||||
throw haxe.io.Error.Custom("tell() failure");
|
||||
return p;
|
||||
}
|
||||
|
||||
public function eof():Bool {
|
||||
return file_eof(__f);
|
||||
}
|
||||
|
||||
@:hlNative("std", "file_eof") static function file_eof(f:FileHandle):Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
@:hlNative("std", "file_read") static function file_read(f:FileHandle, bytes:hl.Bytes, pos:Int, len:Int):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative("std", "file_read_char") static function file_read_char(f:FileHandle):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative("std", "file_close") static function file_close(f:FileHandle):Void {}
|
||||
|
||||
@:hlNative("std", "file_seek") static function file_seek(f:FileHandle, pos:Int, from:Int):Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
@:hlNative("std", "file_tell") static function file_tell(f:FileHandle):Int {
|
||||
return 0;
|
||||
}
|
||||
}
|
86
Kha/Tools/macos/std/hl/_std/sys/io/FileOutput.hx
Normal file
86
Kha/Tools/macos/std/hl/_std/sys/io/FileOutput.hx
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.io;
|
||||
|
||||
import sys.io.File;
|
||||
|
||||
@:coreApi class FileOutput extends haxe.io.Output {
|
||||
private var __f:FileHandle;
|
||||
|
||||
function new(f:FileHandle):Void {
|
||||
__f = f;
|
||||
}
|
||||
|
||||
public override function writeByte(c:Int):Void {
|
||||
if (!file_write_char(__f, c))
|
||||
throw new haxe.io.Eof();
|
||||
}
|
||||
|
||||
public override function writeBytes(s:haxe.io.Bytes, p:Int, l:Int):Int {
|
||||
if (p < 0 || l < 0 || p + l > s.length)
|
||||
throw haxe.io.Error.OutsideBounds;
|
||||
var v = file_write(__f, s.getData(), p, l);
|
||||
if (v <= 0)
|
||||
throw new haxe.io.Eof();
|
||||
return v;
|
||||
}
|
||||
|
||||
public override function flush():Void {
|
||||
if (!file_flush(__f))
|
||||
throw haxe.io.Error.Custom("flush() failure");
|
||||
}
|
||||
|
||||
public override function close():Void {
|
||||
super.close();
|
||||
@:privateAccess FileInput.file_close(__f);
|
||||
__f = null;
|
||||
}
|
||||
|
||||
public function seek(p:Int, pos:FileSeek):Void {
|
||||
if (@:privateAccess !FileInput.file_seek(__f, p, switch (pos) {
|
||||
case SeekBegin: 0;
|
||||
case SeekCur: 1;
|
||||
case SeekEnd: 2;
|
||||
}))
|
||||
throw haxe.io.Error.Custom("seek() failure");
|
||||
}
|
||||
|
||||
public function tell():Int {
|
||||
var p = @:privateAccess FileInput.file_tell(__f);
|
||||
if (p < 0)
|
||||
throw haxe.io.Error.Custom("tell() failure");
|
||||
return p;
|
||||
}
|
||||
|
||||
@:hlNative("std", "file_flush") static function file_flush(f:FileHandle):Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
@:hlNative("std", "file_write") static function file_write(f:FileHandle, bytes:hl.Bytes, pos:Int, len:Int):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative("std", "file_write_char") static function file_write_char(f:FileHandle, v:Int):Bool {
|
||||
return true;
|
||||
}
|
||||
}
|
201
Kha/Tools/macos/std/hl/_std/sys/io/Process.hx
Normal file
201
Kha/Tools/macos/std/hl/_std/sys/io/Process.hx
Normal file
@ -0,0 +1,201 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.io;
|
||||
|
||||
private typedef ProcessHandle = hl.Abstract<"hl_process">;
|
||||
|
||||
private class Stdin extends haxe.io.Output {
|
||||
var p:Dynamic;
|
||||
var buf:haxe.io.Bytes;
|
||||
|
||||
public function new(p) {
|
||||
this.p = p;
|
||||
buf = haxe.io.Bytes.alloc(1);
|
||||
}
|
||||
|
||||
public override function close() {
|
||||
super.close();
|
||||
_stdin_close(p);
|
||||
}
|
||||
|
||||
public override function writeByte(c) {
|
||||
buf.set(0, c);
|
||||
writeBytes(buf, 0, 1);
|
||||
}
|
||||
|
||||
public override function writeBytes(buf:haxe.io.Bytes, pos:Int, len:Int):Int {
|
||||
var v = _stdin_write(p, buf.getData().bytes, pos, len);
|
||||
if (v < 0)
|
||||
throw new haxe.io.Eof();
|
||||
return v;
|
||||
}
|
||||
|
||||
@:hlNative("std", "process_stdin_write") static function _stdin_write(p:ProcessHandle, bytes:hl.Bytes, pos:Int, len:Int):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative("std", "process_stdin_close") static function _stdin_close(p:ProcessHandle):Bool {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private class Stdout extends haxe.io.Input {
|
||||
var p:ProcessHandle;
|
||||
var out:Bool;
|
||||
var buf:haxe.io.Bytes;
|
||||
|
||||
public function new(p, out) {
|
||||
this.p = p;
|
||||
this.out = out;
|
||||
buf = haxe.io.Bytes.alloc(1);
|
||||
}
|
||||
|
||||
public override function readByte() {
|
||||
if (readBytes(buf, 0, 1) == 0)
|
||||
throw haxe.io.Error.Blocked;
|
||||
return buf.get(0);
|
||||
}
|
||||
|
||||
public override function readBytes(str:haxe.io.Bytes, pos:Int, len:Int):Int {
|
||||
var v = out ? _stdout_read(p, str.getData().bytes, pos, len) : _stderr_read(p, str.getData().bytes, pos, len);
|
||||
if (v < 0)
|
||||
throw new haxe.io.Eof();
|
||||
return v;
|
||||
}
|
||||
|
||||
@:hlNative("std", "process_stdout_read") static function _stdout_read(p:ProcessHandle, bytes:hl.Bytes, pos:Int, len:Int):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative("std", "process_stderr_read") static function _stderr_read(p:ProcessHandle, bytes:hl.Bytes, pos:Int, len:Int):Int {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@:access(Sys)
|
||||
@:coreApi class Process {
|
||||
var p:ProcessHandle;
|
||||
|
||||
public var stdout(default, null):haxe.io.Input;
|
||||
public var stderr(default, null):haxe.io.Input;
|
||||
public var stdin(default, null):haxe.io.Output;
|
||||
|
||||
static var isWin = Sys.systemName() == "Windows";
|
||||
|
||||
public function new(cmd:String, ?args:Array<String>, ?detached:Bool):Void {
|
||||
var runCmd = cmd;
|
||||
if (isWin) {
|
||||
var b = new StringBuf();
|
||||
if (args == null) {
|
||||
var exe = Sys.getEnv("COMSPEC");
|
||||
if (exe == null)
|
||||
exe = "cmd.exe";
|
||||
b.add("\"");
|
||||
b.add(exe);
|
||||
b.add("\" /C \"");
|
||||
b.add(cmd);
|
||||
b.addChar('"'.code);
|
||||
} else {
|
||||
b.addChar('"'.code);
|
||||
b.add(cmd);
|
||||
b.addChar('"'.code);
|
||||
for (a in args) {
|
||||
b.add(" \"");
|
||||
var bsCount = 0;
|
||||
for (i in 0...a.length) {
|
||||
switch (StringTools.fastCodeAt(a, i)) {
|
||||
case '"'.code:
|
||||
for (i in 0...bsCount * 2)
|
||||
b.addChar('\\'.code);
|
||||
bsCount = 0;
|
||||
b.add("\\\"");
|
||||
case '\\'.code:
|
||||
bsCount++;
|
||||
case c:
|
||||
for (i in 0...bsCount)
|
||||
b.addChar('\\'.code);
|
||||
bsCount = 0;
|
||||
b.addChar(c);
|
||||
}
|
||||
}
|
||||
// Add remaining backslashes, if any.
|
||||
for (i in 0...bsCount * 2)
|
||||
b.addChar('\\'.code);
|
||||
b.addChar('"'.code);
|
||||
}
|
||||
args = null;
|
||||
}
|
||||
runCmd = b.toString();
|
||||
}
|
||||
@:privateAccess {
|
||||
var aargs = null;
|
||||
if (args != null) {
|
||||
aargs = new hl.NativeArray<hl.Bytes>(args.length);
|
||||
for (i in 0...args.length)
|
||||
aargs[i] = Sys.getPath(args[i]);
|
||||
}
|
||||
p = _run(Sys.getPath(runCmd), aargs, detached);
|
||||
}
|
||||
if (p == null)
|
||||
throw new Sys.SysError("Process creation failure : " + cmd);
|
||||
stdin = new Stdin(p);
|
||||
stdout = new Stdout(p, true);
|
||||
stderr = new Stdout(p, false);
|
||||
}
|
||||
|
||||
public function getPid():Int {
|
||||
return _pid(p);
|
||||
}
|
||||
|
||||
public function exitCode(block:Bool = true):Null<Int> {
|
||||
var running = false;
|
||||
var code = _exit(p, block == false ? new hl.Ref(running) : null);
|
||||
if (block == false)
|
||||
return running ? null : code;
|
||||
return code;
|
||||
}
|
||||
|
||||
public function close():Void {
|
||||
_close(p);
|
||||
}
|
||||
|
||||
public function kill():Void {
|
||||
_kill(p);
|
||||
}
|
||||
|
||||
@:hlNative("std", "process_run") static function _run(cmd:hl.Bytes, args:hl.NativeArray<hl.Bytes>, detached:Bool):ProcessHandle {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "process_exit") static function _exit(p:ProcessHandle, running:hl.Ref<Bool>):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative("std", "process_pid") static function _pid(p:ProcessHandle):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative("std", "process_close") static function _close(p:ProcessHandle):Void {}
|
||||
|
||||
@:hlNative("std", "process_kill") static function _kill(p:ProcessHandle):Void {}
|
||||
}
|
65
Kha/Tools/macos/std/hl/_std/sys/net/Host.hx
Normal file
65
Kha/Tools/macos/std/hl/_std/sys/net/Host.hx
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.net;
|
||||
|
||||
@:coreApi
|
||||
class Host {
|
||||
public var host(default, null):String;
|
||||
|
||||
public var ip(default, null):Int;
|
||||
|
||||
public function new(name:String):Void {
|
||||
host = name;
|
||||
ip = host_resolve(@:privateAccess name.bytes.utf16ToUtf8(0, null));
|
||||
if (ip == -1)
|
||||
throw new Sys.SysError("Unresolved host " + name);
|
||||
}
|
||||
|
||||
public function toString():String {
|
||||
return @:privateAccess String.fromUTF8(host_to_string(ip));
|
||||
}
|
||||
|
||||
public function reverse():String {
|
||||
return @:privateAccess String.fromUTF8(host_reverse(ip));
|
||||
}
|
||||
|
||||
public static function localhost():String {
|
||||
return @:privateAccess String.fromUTF8(host_local());
|
||||
}
|
||||
|
||||
@:hlNative("std", "host_resolve") static function host_resolve(name:hl.Bytes):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative("std", "host_reverse") static function host_reverse(host:Int):hl.Bytes {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "host_to_string") static function host_to_string(host:Int):hl.Bytes {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "host_local") static function host_local():hl.Bytes {
|
||||
return null;
|
||||
}
|
||||
}
|
334
Kha/Tools/macos/std/hl/_std/sys/net/Socket.hx
Normal file
334
Kha/Tools/macos/std/hl/_std/sys/net/Socket.hx
Normal file
@ -0,0 +1,334 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.net;
|
||||
|
||||
import haxe.io.Error;
|
||||
|
||||
#if doc_gen
|
||||
@:noDoc enum SocketHandle {}
|
||||
#else
|
||||
@:noDoc typedef SocketHandle = hl.Abstract<"hl_socket">;
|
||||
#end
|
||||
|
||||
private class SocketOutput extends haxe.io.Output {
|
||||
var sock:Socket;
|
||||
|
||||
public function new(s) {
|
||||
this.sock = s;
|
||||
}
|
||||
|
||||
public override function writeByte(c:Int) {
|
||||
var k = socket_send_char(@:privateAccess sock.__s, c);
|
||||
if (k < 0) {
|
||||
if (k == -1)
|
||||
throw Blocked;
|
||||
throw new haxe.io.Eof();
|
||||
}
|
||||
}
|
||||
|
||||
public override function writeBytes(buf:haxe.io.Bytes, pos:Int, len:Int):Int {
|
||||
if (pos < 0 || len < 0 || pos + len > buf.length)
|
||||
throw haxe.io.Error.OutsideBounds;
|
||||
var n = socket_send(@:privateAccess sock.__s, buf.getData().bytes, pos, len);
|
||||
if (n < 0) {
|
||||
if (n == -1)
|
||||
throw Blocked;
|
||||
throw new haxe.io.Eof();
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
public override function close() {
|
||||
sock.close();
|
||||
}
|
||||
|
||||
@:hlNative("std", "socket_send_char") static function socket_send_char(s:SocketHandle, c:Int):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative("std", "socket_send") static function socket_send(s:SocketHandle, bytes:hl.Bytes, pos:Int, len:Int):Int {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private class SocketInput extends haxe.io.Input {
|
||||
var sock:Socket;
|
||||
|
||||
public function new(s) {
|
||||
sock = s;
|
||||
}
|
||||
|
||||
public override function readByte():Int {
|
||||
var c = socket_recv_char(@:privateAccess sock.__s);
|
||||
if (c < 0) {
|
||||
if (c == -1)
|
||||
throw Blocked;
|
||||
throw new haxe.io.Eof();
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
public override function readBytes(buf:haxe.io.Bytes, pos:Int, len:Int):Int {
|
||||
if (pos < 0 || len < 0 || pos + len > buf.length)
|
||||
throw haxe.io.Error.OutsideBounds;
|
||||
var r = socket_recv(@:privateAccess sock.__s, buf.getData().bytes, pos, len);
|
||||
if (r <= 0) {
|
||||
if (r == -1)
|
||||
throw Blocked;
|
||||
throw new haxe.io.Eof();
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
public override function close() {
|
||||
sock.close();
|
||||
}
|
||||
|
||||
@:hlNative("std", "socket_recv") static function socket_recv(s:SocketHandle, bytes:hl.Bytes, pos:Int, len:Int):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative("std", "socket_recv_char") static function socket_recv_char(s:SocketHandle):Int {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@:coreApi
|
||||
@:keepInit
|
||||
class Socket {
|
||||
private var __s:SocketHandle;
|
||||
|
||||
public var input(default, null):haxe.io.Input;
|
||||
public var output(default, null):haxe.io.Output;
|
||||
public var custom:Dynamic;
|
||||
|
||||
static function __init__():Void {
|
||||
socket_init();
|
||||
}
|
||||
|
||||
public function new():Void {
|
||||
init();
|
||||
}
|
||||
|
||||
function init():Void {
|
||||
if (__s == null)
|
||||
__s = socket_new(false);
|
||||
input = new SocketInput(this);
|
||||
output = new SocketOutput(this);
|
||||
}
|
||||
|
||||
public function close():Void {
|
||||
if (__s != null) {
|
||||
socket_close(__s);
|
||||
__s = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function read():String {
|
||||
return input.readAll().toString();
|
||||
}
|
||||
|
||||
public function write(content:String):Void {
|
||||
output.writeString(content);
|
||||
}
|
||||
|
||||
public function connect(host:Host, port:Int):Void {
|
||||
if (!socket_connect(__s, host.ip, port))
|
||||
throw new Sys.SysError("Failed to connect on " + host.toString() + ":" + port);
|
||||
}
|
||||
|
||||
public function listen(connections:Int):Void {
|
||||
if (!socket_listen(__s, connections))
|
||||
throw new Sys.SysError("listen() failure");
|
||||
}
|
||||
|
||||
public function shutdown(read:Bool, write:Bool):Void {
|
||||
if (!socket_shutdown(__s, read, write))
|
||||
throw new Sys.SysError("shutdown() failure");
|
||||
}
|
||||
|
||||
public function bind(host:Host, port:Int):Void {
|
||||
if (!socket_bind(__s, host.ip, port))
|
||||
throw new Sys.SysError("Cannot bind socket on " + host + ":" + port);
|
||||
}
|
||||
|
||||
public function accept():Socket {
|
||||
var c = socket_accept(__s);
|
||||
if (c == null)
|
||||
return null;
|
||||
var s:Socket = untyped $new(Socket);
|
||||
s.__s = c;
|
||||
s.input = new SocketInput(s);
|
||||
s.output = new SocketOutput(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
public function peer():{host:Host, port:Int} {
|
||||
var ip = 0, port = 0;
|
||||
if (!socket_peer(__s, ip, port))
|
||||
return null;
|
||||
var h:Host = untyped $new(Host);
|
||||
@:privateAccess h.ip = ip;
|
||||
return {host: h, port: port};
|
||||
}
|
||||
|
||||
public function host():{host:Host, port:Int} {
|
||||
var ip = 0, port = 0;
|
||||
if (!socket_host(__s, ip, port))
|
||||
return null;
|
||||
var h:Host = untyped $new(Host);
|
||||
@:privateAccess h.ip = ip;
|
||||
return {host: h, port: port};
|
||||
}
|
||||
|
||||
public function setTimeout(timeout:Float):Void {
|
||||
if (!socket_set_timeout(__s, timeout))
|
||||
throw new Sys.SysError("setTimeout() failure");
|
||||
}
|
||||
|
||||
public function waitForRead():Void {
|
||||
select([this], null, null, null);
|
||||
}
|
||||
|
||||
public function setBlocking(b:Bool):Void {
|
||||
if (!socket_set_blocking(__s, b))
|
||||
throw new Sys.SysError("setBlocking() failure");
|
||||
}
|
||||
|
||||
public function setFastSend(b:Bool):Void {
|
||||
if (!socket_set_fast_send(__s, b))
|
||||
throw new Sys.SysError("setFastSend() failure");
|
||||
}
|
||||
|
||||
// TODO : use TLS when multithread added
|
||||
static var tmp:hl.Bytes = null;
|
||||
static var curTmpSize = 0;
|
||||
|
||||
static function makeArray(a:Array<Socket>):hl.NativeArray<SocketHandle> {
|
||||
if (a == null)
|
||||
return null;
|
||||
var arr = new hl.NativeArray(a.length);
|
||||
for (i in 0...a.length)
|
||||
arr[i] = a[i].__s;
|
||||
return arr;
|
||||
}
|
||||
|
||||
static function outArray(a:hl.NativeArray<SocketHandle>, original:Array<Socket>):Array<Socket> {
|
||||
var out = [];
|
||||
if (a == null)
|
||||
return out;
|
||||
var i = 0, p = 0;
|
||||
var max = original.length;
|
||||
while (i < max) {
|
||||
var sh = a[i++];
|
||||
if (sh == null)
|
||||
break;
|
||||
while (original[p].__s != sh)
|
||||
p++;
|
||||
out.push(original[p++]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public static function select(read:Array<Socket>, write:Array<Socket>, others:Array<Socket>,
|
||||
?timeout:Float):{read:Array<Socket>, write:Array<Socket>, others:Array<Socket>} {
|
||||
var sread = makeArray(read);
|
||||
var swrite = makeArray(write);
|
||||
var sothers = makeArray(others);
|
||||
var tmpSize = 0;
|
||||
if (sread != null)
|
||||
tmpSize += socket_fd_size(sread.length);
|
||||
if (swrite != null)
|
||||
tmpSize += socket_fd_size(swrite.length);
|
||||
if (sothers != null)
|
||||
tmpSize += socket_fd_size(sothers.length);
|
||||
if (tmpSize > curTmpSize) {
|
||||
tmp = new hl.Bytes(tmpSize);
|
||||
curTmpSize = tmpSize;
|
||||
}
|
||||
if (!socket_select(sread, swrite, sothers, tmp, curTmpSize, timeout == null ? -1 : timeout))
|
||||
throw "Error while waiting on socket";
|
||||
return {
|
||||
read: outArray(sread, read),
|
||||
write: outArray(swrite, write),
|
||||
others: outArray(sothers, others),
|
||||
};
|
||||
}
|
||||
|
||||
@:hlNative("std", "socket_init") static function socket_init():Void {}
|
||||
|
||||
@:hlNative("std", "socket_new") static function socket_new(udp:Bool):SocketHandle {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "socket_close") static function socket_close(s:SocketHandle):Void {}
|
||||
|
||||
@:hlNative("std", "socket_connect") static function socket_connect(s:SocketHandle, host:Int, port:Int):Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
@:hlNative("std", "socket_listen") static function socket_listen(s:SocketHandle, count:Int):Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
@:hlNative("std", "socket_bind") static function socket_bind(s:SocketHandle, host:Int, port:Int):Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
@:hlNative("std", "socket_accept") static function socket_accept(s:SocketHandle):SocketHandle {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "socket_peer") static function socket_peer(s:SocketHandle, host:hl.Ref<Int>, port:hl.Ref<Int>):Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
@:hlNative("std", "socket_host") static function socket_host(s:SocketHandle, host:hl.Ref<Int>, port:hl.Ref<Int>):Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
@:hlNative("std", "socket_set_timeout") static function socket_set_timeout(s:SocketHandle, timeout:Float):Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
@:hlNative("std", "socket_shutdown") static function socket_shutdown(s:SocketHandle, read:Bool, write:Bool):Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
@:hlNative("std", "socket_set_blocking") static function socket_set_blocking(s:SocketHandle, b:Bool):Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
@:hlNative("std", "socket_set_fast_send") static function socket_set_fast_send(s:SocketHandle, b:Bool):Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
@:hlNative("std", "socket_fd_size") static function socket_fd_size(count:Int):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative("std", "socket_select") static function socket_select(read:hl.NativeArray<SocketHandle>, write:hl.NativeArray<SocketHandle>,
|
||||
other:hl.NativeArray<SocketHandle>, tmpData:hl.Bytes, tmpSize:Int, timeout:Float):Bool {
|
||||
return false;
|
||||
}
|
||||
}
|
81
Kha/Tools/macos/std/hl/_std/sys/net/UdpSocket.hx
Normal file
81
Kha/Tools/macos/std/hl/_std/sys/net/UdpSocket.hx
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.net;
|
||||
|
||||
import sys.net.Socket;
|
||||
import haxe.io.Error;
|
||||
|
||||
class UdpSocket extends Socket {
|
||||
public function new() {
|
||||
super();
|
||||
}
|
||||
|
||||
override function init():Void {
|
||||
__s = Socket.socket_new(true);
|
||||
super.init();
|
||||
}
|
||||
|
||||
public function sendTo(buf:haxe.io.Bytes, pos:Int, len:Int, addr:Address):Int {
|
||||
if (pos < 0 || len < 0 || pos + len > buf.length)
|
||||
throw OutsideBounds;
|
||||
var ret = socket_send_to(__s, (buf : hl.Bytes).offset(pos), len, addr.host, addr.port);
|
||||
if (ret < 0) {
|
||||
if (ret == -1)
|
||||
throw Blocked;
|
||||
throw new haxe.io.Eof();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public function readFrom(buf:haxe.io.Bytes, pos:Int, len:Int, addr:Address):Int {
|
||||
var host = 0, port = 0;
|
||||
if (pos < 0 || len < 0 || pos + len > buf.length)
|
||||
throw OutsideBounds;
|
||||
var ret = socket_recv_from(__s, (buf : hl.Bytes).offset(pos), len, host, port);
|
||||
if (ret <= 0) {
|
||||
if (ret == -1)
|
||||
throw Blocked;
|
||||
throw new haxe.io.Eof();
|
||||
}
|
||||
addr.host = host;
|
||||
addr.port = port;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public function setBroadcast(b:Bool):Void {
|
||||
if (!socket_set_broadcast(__s, b))
|
||||
throw new Sys.SysError("setBroadcast() failure");
|
||||
}
|
||||
|
||||
@:hlNative("std", "socket_send_to") static function socket_send_to(s:SocketHandle, bytes:hl.Bytes, len:Int, host:Int, port:Int):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:hlNative("std", "socket_set_broadcast") static function socket_set_broadcast(s:SocketHandle, b:Bool):Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
@:hlNative("std", "socket_recv_from") static function socket_recv_from(s:SocketHandle, bytes:hl.Bytes, len:Int, host:hl.Ref<Int>, port:hl.Ref<Int>):Int {
|
||||
return 0;
|
||||
}
|
||||
}
|
182
Kha/Tools/macos/std/hl/_std/sys/ssl/Certificate.hx
Normal file
182
Kha/Tools/macos/std/hl/_std/sys/ssl/Certificate.hx
Normal file
@ -0,0 +1,182 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.ssl;
|
||||
|
||||
import sys.ssl.Lib;
|
||||
|
||||
@:noDoc
|
||||
typedef CertificatePtr = hl.Abstract<"hl_ssl_cert">;
|
||||
|
||||
@:coreApi
|
||||
class Certificate {
|
||||
var __h:Null<Certificate>;
|
||||
var __x:CertificatePtr;
|
||||
|
||||
@:allow(sys.ssl.Socket)
|
||||
function new(x:CertificatePtr, ?h:Certificate) {
|
||||
__x = x;
|
||||
__h = h;
|
||||
}
|
||||
|
||||
public static function loadFile(file:String):Certificate {
|
||||
return new Certificate(cert_load_file(@:privateAccess file.toUtf8()));
|
||||
}
|
||||
|
||||
public static function loadPath(path:String):Certificate {
|
||||
return new Certificate(cert_load_path(@:privateAccess path.toUtf8()));
|
||||
}
|
||||
|
||||
public static function fromString(str:String):Certificate {
|
||||
return new Certificate(cert_add_pem(null, @:privateAccess str.toUtf8()));
|
||||
}
|
||||
|
||||
public static function loadDefaults():Certificate {
|
||||
var x = cert_load_defaults();
|
||||
if (x != null)
|
||||
return new Certificate(x);
|
||||
|
||||
var defPaths = null;
|
||||
switch (Sys.systemName()) {
|
||||
case "Linux":
|
||||
defPaths = [
|
||||
"/etc/ssl/certs/ca-certificates.crt", // Debian/Ubuntu/Gentoo etc.
|
||||
"/etc/pki/tls/certs/ca-bundle.crt", // Fedora/RHEL
|
||||
"/etc/ssl/ca-bundle.pem", // OpenSUSE
|
||||
"/etc/pki/tls/cacert.pem", // OpenELEC
|
||||
"/etc/ssl/certs", // SLES10/SLES11
|
||||
"/system/etc/security/cacerts" // Android
|
||||
];
|
||||
case "BSD":
|
||||
defPaths = [
|
||||
"/usr/local/share/certs/ca-root-nss.crt", // FreeBSD/DragonFly
|
||||
"/etc/ssl/cert.pem", // OpenBSD
|
||||
"/etc/openssl/certs/ca-certificates.crt", // NetBSD
|
||||
];
|
||||
case "Android":
|
||||
defPaths = ["/system/etc/security/cacerts"];
|
||||
default:
|
||||
}
|
||||
if (defPaths != null) {
|
||||
for (path in defPaths) {
|
||||
if (sys.FileSystem.exists(path)) {
|
||||
if (sys.FileSystem.isDirectory(path))
|
||||
return loadPath(path);
|
||||
else
|
||||
return loadFile(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public var commonName(get, null):Null<String>;
|
||||
public var altNames(get, null):Array<String>;
|
||||
public var notBefore(get, null):Date;
|
||||
public var notAfter(get, null):Date;
|
||||
|
||||
function get_commonName():Null<String> {
|
||||
return subject("CN");
|
||||
}
|
||||
|
||||
function get_altNames():Array<String> {
|
||||
var a = cert_get_altnames(__x);
|
||||
return [for (e in a) @:privateAccess String.fromUCS2(e)];
|
||||
}
|
||||
|
||||
public function subject(field:String):Null<String> {
|
||||
var s = cert_get_subject(__x, @:privateAccess field.toUtf8());
|
||||
return s == null ? null : @:privateAccess String.fromUCS2(cast s);
|
||||
}
|
||||
|
||||
public function issuer(field:String):Null<String> {
|
||||
var s = cert_get_issuer(__x, @:privateAccess field.toUtf8());
|
||||
return s == null ? null : @:privateAccess String.fromUCS2(cast s);
|
||||
}
|
||||
|
||||
function get_notBefore():Date {
|
||||
var a = cert_get_notbefore(__x);
|
||||
return new Date(a[0], a[1] - 1, a[2], a[3], a[4], a[5]);
|
||||
}
|
||||
|
||||
function get_notAfter():Date {
|
||||
var a = cert_get_notafter(__x);
|
||||
return new Date(a[0], a[1] - 1, a[2], a[3], a[4], a[5]);
|
||||
}
|
||||
|
||||
public function next():Null<Certificate> {
|
||||
var n = cert_get_next(__x);
|
||||
return n == null ? null : new Certificate(n, __h == null ? this : __h);
|
||||
}
|
||||
|
||||
public function add(pem:String):Void {
|
||||
cert_add_pem(__x, @:privateAccess pem.toUtf8());
|
||||
}
|
||||
|
||||
public function addDER(der:haxe.io.Bytes):Void {
|
||||
cert_add_der(__x, @:privateAccess der.b, @:privateAccess der.length);
|
||||
}
|
||||
|
||||
@:hlNative("ssl", "cert_load_defaults") static function cert_load_defaults():CertificatePtr {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("ssl", "cert_load_file") static function cert_load_file(file:hl.Bytes):CertificatePtr {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("ssl", "cert_load_path") static function cert_load_path(path:hl.Bytes):CertificatePtr {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("ssl", "cert_get_subject") static function cert_get_subject(cert:CertificatePtr, obj:hl.Bytes):hl.Bytes {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("ssl", "cert_get_issuer") static function cert_get_issuer(cert:CertificatePtr, obj:hl.Bytes):hl.Bytes {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("ssl", "cert_get_altnames") static function cert_get_altnames(cert:CertificatePtr):hl.NativeArray<hl.Bytes> {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("ssl", "cert_get_notbefore") static function cert_get_notbefore(cert:CertificatePtr):hl.NativeArray<Int> {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("ssl", "cert_get_notafter") static function cert_get_notafter(cert:CertificatePtr):hl.NativeArray<Int> {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("ssl", "cert_get_next") static function cert_get_next(cert:CertificatePtr):Null<CertificatePtr> {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("ssl", "cert_add_pem") static function cert_add_pem(cert:Null<CertificatePtr>, data:hl.Bytes):CertificatePtr {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("ssl", "cert_add_der") static function cert_add_der(cert:Null<CertificatePtr>, data:hl.Bytes, len:Int):CertificatePtr {
|
||||
return null;
|
||||
}
|
||||
}
|
98
Kha/Tools/macos/std/hl/_std/sys/ssl/Context.hx
Normal file
98
Kha/Tools/macos/std/hl/_std/sys/ssl/Context.hx
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.ssl;
|
||||
|
||||
private typedef ConfigPtr = hl.Abstract<"mbedtls_ssl_config">;
|
||||
private typedef ContextPtr = hl.Abstract<"mbedtls_ssl_context">;
|
||||
|
||||
@:keep class SNICbResult {
|
||||
public var cert:Certificate.CertificatePtr;
|
||||
public var key:Key.KeyPtr;
|
||||
|
||||
public function new(cert:Certificate, key:Key) {
|
||||
this.cert = @:privateAccess cert.__x;
|
||||
this.key = @:privateAccess key.__k;
|
||||
}
|
||||
}
|
||||
|
||||
@:hlNative("ssl", "ssl_")
|
||||
abstract Context(ContextPtr) {
|
||||
public function new(config) {
|
||||
this = ssl_new(config);
|
||||
}
|
||||
|
||||
public function close():Void {}
|
||||
|
||||
public function handshake():Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function recvChar():Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function sendChar(c:Int):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getPeerCertificate():Certificate.CertificatePtr {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function recv(bytes:hl.Bytes, pos:Int, len:Int):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function send(bytes:hl.Bytes, pos:Int, len:Int):Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function setSocket(socket:sys.net.Socket.SocketHandle):Void {}
|
||||
|
||||
public function setHostname(name:hl.Bytes):Void {}
|
||||
|
||||
@:hlNative("ssl", "ssl_new") static function ssl_new(conf:Config):ContextPtr {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@:hlNative("ssl", "conf_")
|
||||
abstract Config(ConfigPtr) {
|
||||
public function new(server:Bool) {
|
||||
this = conf_new(server);
|
||||
}
|
||||
|
||||
public function setCert(cert:Certificate.CertificatePtr, pkey:Key.KeyPtr):Void {}
|
||||
|
||||
public function setCa(ca:Certificate.CertificatePtr):Void {}
|
||||
|
||||
public function close():Void {}
|
||||
|
||||
public function setVerify(mode:Int):Void {}
|
||||
|
||||
public function setServernameCallback(cb:hl.Bytes->SNICbResult):Void {}
|
||||
|
||||
@:hlNative("ssl", "conf_new") static function conf_new(server:Bool):ConfigPtr {
|
||||
return null;
|
||||
}
|
||||
}
|
56
Kha/Tools/macos/std/hl/_std/sys/ssl/Digest.hx
Normal file
56
Kha/Tools/macos/std/hl/_std/sys/ssl/Digest.hx
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.ssl;
|
||||
|
||||
import sys.ssl.Lib;
|
||||
|
||||
@:coreApi
|
||||
class Digest {
|
||||
public static function make(data:haxe.io.Bytes, alg:DigestAlgorithm):haxe.io.Bytes {
|
||||
var size = 0;
|
||||
var b = @:privateAccess dgst_make(data.b, data.length, (alg : String).toUtf8(), size);
|
||||
return @:privateAccess new haxe.io.Bytes(b, size);
|
||||
}
|
||||
|
||||
public static function sign(data:haxe.io.Bytes, privKey:Key, alg:DigestAlgorithm):haxe.io.Bytes {
|
||||
var size = 0;
|
||||
var b = @:privateAccess dgst_sign(data.b, data.length, privKey.__k, (alg : String).toUtf8(), size);
|
||||
return @:privateAccess new haxe.io.Bytes(b, size);
|
||||
}
|
||||
|
||||
public static function verify(data:haxe.io.Bytes, signature:haxe.io.Bytes, pubKey:Key, alg:DigestAlgorithm):Bool {
|
||||
return @:privateAccess dgst_verify(data.b, data.length, signature.b, signature.length, pubKey.__k, (alg : String).toUtf8());
|
||||
}
|
||||
|
||||
@:hlNative("ssl", "dgst_make") static function dgst_make(data:hl.Bytes, len:Int, alg:hl.Bytes, size:hl.Ref<Int>):hl.Bytes {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("ssl", "dgst_sign") static function dgst_sign(data:hl.Bytes, len:Int, key:sys.ssl.Key.KeyPtr, alg:hl.Bytes, size:hl.Ref<Int>):hl.Bytes {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("ssl", "dgst_verify") static function dgst_verify(data:hl.Bytes, dlen:Int, sign:hl.Bytes, slen:Int, key:sys.ssl.Key.KeyPtr, alg:hl.Bytes):Bool {
|
||||
return false;
|
||||
}
|
||||
}
|
62
Kha/Tools/macos/std/hl/_std/sys/ssl/Key.hx
Normal file
62
Kha/Tools/macos/std/hl/_std/sys/ssl/Key.hx
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.ssl;
|
||||
|
||||
import sys.ssl.Lib;
|
||||
|
||||
@:noDoc
|
||||
typedef KeyPtr = hl.Abstract<"hl_ssl_pkey">;
|
||||
|
||||
@:coreApi
|
||||
class Key {
|
||||
private var __k:KeyPtr;
|
||||
|
||||
private function new(k:KeyPtr) {
|
||||
__k = k;
|
||||
}
|
||||
|
||||
public static function loadFile(file:String, ?isPublic:Bool, ?pass:String):Key {
|
||||
var data = sys.io.File.getBytes(file);
|
||||
var start = data.getString(0, 11);
|
||||
if (start == "-----BEGIN ")
|
||||
return readPEM(data.toString(), isPublic == true, pass);
|
||||
else
|
||||
return readDER(data, isPublic == true);
|
||||
}
|
||||
|
||||
public static function readPEM(data:String, isPublic:Bool, ?pass:String):Key {
|
||||
return new Key(key_from_pem(@:privateAccess data.toUtf8(), isPublic, pass == null ? null : @:privateAccess pass.toUtf8()));
|
||||
}
|
||||
|
||||
public static function readDER(data:haxe.io.Bytes, isPublic:Bool):Key {
|
||||
return new Key(key_from_der(@:privateAccess data.b, @:privateAccess data.length, isPublic));
|
||||
}
|
||||
|
||||
@:hlNative("ssl", "key_from_pem") static function key_from_pem(data:hl.Bytes, pub:Bool, pass:Null<hl.Bytes>):KeyPtr {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("ssl", "key_from_der") static function key_from_der(data:hl.Bytes, len:Int, pub:Bool):KeyPtr {
|
||||
return null;
|
||||
}
|
||||
}
|
32
Kha/Tools/macos/std/hl/_std/sys/ssl/Lib.hx
Normal file
32
Kha/Tools/macos/std/hl/_std/sys/ssl/Lib.hx
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.ssl;
|
||||
|
||||
@:noDoc @:keep
|
||||
class Lib {
|
||||
static function __init__():Void {
|
||||
ssl_init();
|
||||
}
|
||||
|
||||
@:hlNative("ssl", "ssl_init") static function ssl_init() {};
|
||||
}
|
255
Kha/Tools/macos/std/hl/_std/sys/ssl/Socket.hx
Normal file
255
Kha/Tools/macos/std/hl/_std/sys/ssl/Socket.hx
Normal file
@ -0,0 +1,255 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.ssl;
|
||||
|
||||
import sys.ssl.Lib;
|
||||
import sys.ssl.Key.KeyPtr;
|
||||
import sys.ssl.Certificate.CertificatePtr;
|
||||
import sys.net.Socket.SocketHandle;
|
||||
|
||||
private class SocketInput extends haxe.io.Input {
|
||||
@:allow(sys.ssl.Socket) private var __s:Socket;
|
||||
|
||||
public function new(s:Socket) {
|
||||
this.__s = s;
|
||||
}
|
||||
|
||||
public override function readByte() {
|
||||
__s.handshake();
|
||||
var r = @:privateAccess __s.ssl.recvChar();
|
||||
if (r == -1)
|
||||
throw haxe.io.Error.Blocked;
|
||||
else if (r < 0)
|
||||
throw new haxe.io.Eof();
|
||||
return r;
|
||||
}
|
||||
|
||||
public override function readBytes(buf:haxe.io.Bytes, pos:Int, len:Int):Int {
|
||||
if (pos < 0 || len < 0 || ((pos + len) : UInt) > (buf.length : UInt))
|
||||
throw haxe.io.Error.OutsideBounds;
|
||||
__s.handshake();
|
||||
var r = @:privateAccess __s.ssl.recv(buf, pos, len);
|
||||
if (r == -1)
|
||||
throw haxe.io.Error.Blocked;
|
||||
else if (r <= 0)
|
||||
throw new haxe.io.Eof();
|
||||
return r;
|
||||
}
|
||||
|
||||
public override function close() {
|
||||
super.close();
|
||||
if (__s != null)
|
||||
__s.close();
|
||||
}
|
||||
}
|
||||
|
||||
private class SocketOutput extends haxe.io.Output {
|
||||
@:allow(sys.ssl.Socket) private var __s:Socket;
|
||||
|
||||
public function new(s:Socket) {
|
||||
this.__s = s;
|
||||
}
|
||||
|
||||
public override function writeByte(c:Int) {
|
||||
__s.handshake();
|
||||
var r = @:privateAccess __s.ssl.sendChar(c);
|
||||
if (r == -1)
|
||||
throw haxe.io.Error.Blocked;
|
||||
else if (r < 0)
|
||||
throw new haxe.io.Eof();
|
||||
}
|
||||
|
||||
public override function writeBytes(buf:haxe.io.Bytes, pos:Int, len:Int):Int {
|
||||
if (pos < 0 || len < 0 || ((pos + len) : UInt) > (buf.length : UInt))
|
||||
throw haxe.io.Error.OutsideBounds;
|
||||
__s.handshake();
|
||||
var r = @:privateAccess __s.ssl.send(buf, pos, len);
|
||||
if (r == -1)
|
||||
throw haxe.io.Error.Blocked;
|
||||
else if (r < 0)
|
||||
throw new haxe.io.Eof();
|
||||
return r;
|
||||
}
|
||||
|
||||
public override function close() {
|
||||
super.close();
|
||||
if (__s != null)
|
||||
__s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@:coreApi @:access(sys.net.Socket)
|
||||
class Socket extends sys.net.Socket {
|
||||
public static var DEFAULT_VERIFY_CERT:Null<Bool> = true;
|
||||
|
||||
public static var DEFAULT_CA:Null<Certificate>;
|
||||
|
||||
private var conf:Context.Config;
|
||||
private var ssl:Context;
|
||||
|
||||
public var verifyCert:Null<Bool>;
|
||||
|
||||
private var caCert:Null<Certificate>;
|
||||
private var hostname:String;
|
||||
|
||||
private var ownCert:Null<Certificate>;
|
||||
private var ownKey:Null<Key>;
|
||||
private var altSNIContexts:Null<Array<{match:String->Bool, key:Key, cert:Certificate}>>;
|
||||
private var sniCallback:hl.Bytes->Context.SNICbResult;
|
||||
private var handshakeDone:Bool;
|
||||
private var isBlocking:Bool = true;
|
||||
|
||||
private override function init():Void {
|
||||
__s = sys.net.Socket.socket_new(false);
|
||||
input = new SocketInput(this);
|
||||
output = new SocketOutput(this);
|
||||
if (DEFAULT_VERIFY_CERT && DEFAULT_CA == null) {
|
||||
try {
|
||||
DEFAULT_CA = Certificate.loadDefaults();
|
||||
} catch (e:Dynamic) {}
|
||||
}
|
||||
verifyCert = DEFAULT_VERIFY_CERT;
|
||||
caCert = DEFAULT_CA;
|
||||
}
|
||||
|
||||
public override function connect(host:sys.net.Host, port:Int):Void {
|
||||
conf = buildConfig(false);
|
||||
ssl = new Context(conf);
|
||||
ssl.setSocket(__s);
|
||||
handshakeDone = false;
|
||||
if (hostname == null)
|
||||
hostname = host.host;
|
||||
if (hostname != null)
|
||||
ssl.setHostname(@:privateAccess hostname.toUtf8());
|
||||
if (!sys.net.Socket.socket_connect(__s, host.ip, port))
|
||||
throw new Sys.SysError("Failed to connect on " + host.toString() + ":" + port);
|
||||
if (isBlocking)
|
||||
handshake();
|
||||
}
|
||||
|
||||
public function handshake():Void {
|
||||
if (!handshakeDone) {
|
||||
var r = ssl.handshake();
|
||||
if (r == 0)
|
||||
handshakeDone = true;
|
||||
else if (r == -1)
|
||||
throw haxe.io.Error.Blocked;
|
||||
else
|
||||
throw new haxe.io.Eof();
|
||||
}
|
||||
}
|
||||
|
||||
override function setBlocking(b:Bool):Void {
|
||||
super.setBlocking(b);
|
||||
isBlocking = b;
|
||||
}
|
||||
|
||||
public function setCA(cert:Certificate):Void {
|
||||
caCert = cert;
|
||||
}
|
||||
|
||||
public function setHostname(name:String):Void {
|
||||
hostname = name;
|
||||
}
|
||||
|
||||
public function setCertificate(cert:Certificate, key:Key):Void {
|
||||
ownCert = cert;
|
||||
ownKey = key;
|
||||
}
|
||||
|
||||
public override function close():Void {
|
||||
if (ssl != null)
|
||||
ssl.close();
|
||||
if (conf != null)
|
||||
conf.close();
|
||||
if (altSNIContexts != null)
|
||||
sniCallback = null;
|
||||
sys.net.Socket.socket_close(__s);
|
||||
var input:SocketInput = cast input;
|
||||
var output:SocketOutput = cast output;
|
||||
@:privateAccess input.__s = output.__s = null;
|
||||
input.close();
|
||||
output.close();
|
||||
}
|
||||
|
||||
public function addSNICertificate(cbServernameMatch:String->Bool, cert:Certificate, key:Key):Void {
|
||||
if (altSNIContexts == null)
|
||||
altSNIContexts = [];
|
||||
altSNIContexts.push({match: cbServernameMatch, cert: cert, key: key});
|
||||
}
|
||||
|
||||
public override function bind(host:sys.net.Host, port:Int):Void {
|
||||
conf = buildConfig(true);
|
||||
|
||||
sys.net.Socket.socket_bind(__s, host.ip, port);
|
||||
}
|
||||
|
||||
public override function accept():Socket {
|
||||
var c = sys.net.Socket.socket_accept(__s);
|
||||
if(c == null)
|
||||
throw "Blocking";
|
||||
var cssl = new Context(conf);
|
||||
cssl.setSocket(c);
|
||||
|
||||
var s = Type.createEmptyInstance(sys.ssl.Socket);
|
||||
s.__s = c;
|
||||
s.ssl = cssl;
|
||||
s.input = new SocketInput(s);
|
||||
s.output = new SocketOutput(s);
|
||||
s.handshakeDone = false;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
public function peerCertificate():sys.ssl.Certificate {
|
||||
var x = ssl.getPeerCertificate();
|
||||
return x == null ? null : new sys.ssl.Certificate(x);
|
||||
}
|
||||
|
||||
private function buildConfig(server:Bool):Context.Config {
|
||||
var conf = new Context.Config(server);
|
||||
|
||||
if (ownCert != null && ownKey != null)
|
||||
conf.setCert(@:privateAccess ownCert.__x, @:privateAccess ownKey.__k);
|
||||
|
||||
if (altSNIContexts != null) {
|
||||
sniCallback = function(servername:hl.Bytes):Context.SNICbResult {
|
||||
var servername = @:privateAccess String.fromUTF8(servername);
|
||||
for (c in altSNIContexts) {
|
||||
if (c.match(servername))
|
||||
return new Context.SNICbResult(c.cert, c.key);
|
||||
}
|
||||
if (ownKey != null && ownCert != null)
|
||||
return new Context.SNICbResult(ownCert, ownKey);
|
||||
return null;
|
||||
}
|
||||
conf.setServernameCallback(sniCallback);
|
||||
}
|
||||
|
||||
if (caCert != null)
|
||||
conf.setCa(caCert == null ? null : @:privateAccess caCert.__x);
|
||||
conf.setVerify(if (verifyCert) 1 else if (verifyCert == null) 2 else 0);
|
||||
|
||||
return conf;
|
||||
}
|
||||
}
|
52
Kha/Tools/macos/std/hl/_std/sys/thread/Deque.hx
Normal file
52
Kha/Tools/macos/std/hl/_std/sys/thread/Deque.hx
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.thread;
|
||||
|
||||
#if doc_gen
|
||||
@:coreApi extern class Deque<T> {
|
||||
function new():Void;
|
||||
function add(i:T):Void;
|
||||
function push(i:T):Void;
|
||||
function pop(block:Bool):Null<T>;
|
||||
}
|
||||
#else
|
||||
|
||||
@:hlNative("std", "deque_")
|
||||
abstract Deque<T>(hl.Abstract<"hl_deque">) {
|
||||
public function new() {
|
||||
this = alloc();
|
||||
}
|
||||
|
||||
public function add(i:T) {}
|
||||
|
||||
public function push(i:T) {}
|
||||
|
||||
public function pop(block:Bool):Null<T> {
|
||||
return null;
|
||||
}
|
||||
|
||||
static function alloc() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
#end
|
87
Kha/Tools/macos/std/hl/_std/sys/thread/Lock.hx
Normal file
87
Kha/Tools/macos/std/hl/_std/sys/thread/Lock.hx
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.thread;
|
||||
|
||||
|
||||
#if (hl_ver >= version("1.11.0"))
|
||||
|
||||
typedef LockHandle = hl.Abstract<"hl_lock">;
|
||||
|
||||
@:coreApi
|
||||
@:hlNative("std")
|
||||
class Lock {
|
||||
var handle : LockHandle;
|
||||
|
||||
public function new() {
|
||||
handle = lock_create();
|
||||
}
|
||||
|
||||
public function wait( ?timeout : Float ) : Bool {
|
||||
return lock_wait(handle, timeout);
|
||||
}
|
||||
|
||||
public function release( ) : Void {
|
||||
lock_release(handle);
|
||||
}
|
||||
|
||||
static function lock_wait( handle : LockHandle, ?timeout : Float ) : Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
static function lock_release( handle : LockHandle ) : Void { }
|
||||
|
||||
static function lock_create( ) : LockHandle {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@:coreApi
|
||||
class Lock {
|
||||
var deque:sys.thread.Deque<Bool>;
|
||||
|
||||
public function new():Void {
|
||||
deque = new Deque<Null<Bool>>();
|
||||
}
|
||||
|
||||
public function wait(?timeout:Float):Bool {
|
||||
if (timeout == null) {
|
||||
deque.pop(true);
|
||||
return true;
|
||||
}
|
||||
var targetTime = haxe.Timer.stamp() + timeout;
|
||||
do {
|
||||
if (deque.pop(false) != null) {
|
||||
return true;
|
||||
}
|
||||
} while (haxe.Timer.stamp() < targetTime);
|
||||
return false;
|
||||
}
|
||||
|
||||
public function release():Void {
|
||||
deque.push(true);
|
||||
}
|
||||
}
|
||||
|
||||
#end
|
52
Kha/Tools/macos/std/hl/_std/sys/thread/Mutex.hx
Normal file
52
Kha/Tools/macos/std/hl/_std/sys/thread/Mutex.hx
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.thread;
|
||||
|
||||
#if doc_gen
|
||||
@:coreApi
|
||||
extern class Mutex {
|
||||
function new():Void;
|
||||
function acquire():Void;
|
||||
function tryAcquire():Bool;
|
||||
function release():Void;
|
||||
}
|
||||
#else
|
||||
|
||||
abstract Mutex(hl.Abstract<"hl_mutex">) {
|
||||
public function new() {
|
||||
this = alloc(true);
|
||||
}
|
||||
|
||||
@:hlNative("std", "mutex_acquire") public function acquire() {}
|
||||
|
||||
@:hlNative("std", "mutex_try_acquire") public function tryAcquire():Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
@:hlNative("std", "mutex_release") public function release() {}
|
||||
|
||||
@:hlNative("std", "mutex_alloc") public static function alloc(b:Bool) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
#end
|
180
Kha/Tools/macos/std/hl/_std/sys/thread/Thread.hx
Normal file
180
Kha/Tools/macos/std/hl/_std/sys/thread/Thread.hx
Normal file
@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.thread;
|
||||
|
||||
private typedef ThreadImpl = HaxeThread;
|
||||
|
||||
abstract Thread(ThreadImpl) from ThreadImpl {
|
||||
public var events(get,never):EventLoop;
|
||||
|
||||
public inline function sendMessage(msg:Dynamic) {
|
||||
this.sendMessage(msg);
|
||||
}
|
||||
|
||||
public static inline function readMessage(block = true):Dynamic {
|
||||
return HaxeThread.current().readMessage(block);
|
||||
}
|
||||
|
||||
public static inline function create(job:()->Void):Thread {
|
||||
return HaxeThread.create(job, false);
|
||||
}
|
||||
|
||||
public static inline function runWithEventLoop(job:()->Void):Void {
|
||||
HaxeThread.runWithEventLoop(job);
|
||||
}
|
||||
|
||||
public static inline function createWithEventLoop(job:()->Void):Thread {
|
||||
return HaxeThread.create(job, true);
|
||||
}
|
||||
|
||||
public static function current():Thread {
|
||||
return HaxeThread.current();
|
||||
}
|
||||
|
||||
function get_events():EventLoop {
|
||||
if(this.events == null)
|
||||
throw new NoEventLoopException();
|
||||
return this.events;
|
||||
}
|
||||
|
||||
@:keep
|
||||
static public function processEvents() {
|
||||
HaxeThread.current().events.loop();
|
||||
}
|
||||
}
|
||||
|
||||
private typedef ThreadHandle = hl.Abstract<"hl_thread">;
|
||||
|
||||
private class HaxeThread {
|
||||
static var mainThreadHandle:ThreadHandle;
|
||||
static var mainThread:HaxeThread;
|
||||
static var threads:Array<{thread:HaxeThread, handle:ThreadHandle}>;
|
||||
static var threadsMutex:Mutex;
|
||||
|
||||
static function __init__() {
|
||||
mainThreadHandle = currentHandle();
|
||||
threadsMutex = new Mutex();
|
||||
threads = [];
|
||||
mainThread = new HaxeThread();
|
||||
mainThread.events = new EventLoop();
|
||||
}
|
||||
|
||||
public var events(default,null):Null<EventLoop>;
|
||||
final messages = new Deque();
|
||||
|
||||
static var ids = 0;
|
||||
var id = ids++;
|
||||
|
||||
@:hlNative("std", "thread_create")
|
||||
static function createHandle(callb:Void->Void):ThreadHandle {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:hlNative("std", "thread_current")
|
||||
static function currentHandle():ThreadHandle {
|
||||
return null;
|
||||
}
|
||||
|
||||
static public function current():HaxeThread {
|
||||
var handle = currentHandle();
|
||||
if(handle == mainThreadHandle) {
|
||||
return mainThread;
|
||||
}
|
||||
threadsMutex.acquire();
|
||||
var thread = null;
|
||||
for(item in threads) {
|
||||
if(item.handle == handle) {
|
||||
thread = item.thread;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(thread == null) {
|
||||
thread = new HaxeThread();
|
||||
threads.push({thread:thread, handle:handle});
|
||||
}
|
||||
threadsMutex.release();
|
||||
return thread;
|
||||
}
|
||||
|
||||
public static function create(callb:()->Void, withEventLoop:Bool):Thread {
|
||||
var item = {handle:null, thread:new HaxeThread()};
|
||||
threadsMutex.acquire();
|
||||
threads.push(item);
|
||||
threadsMutex.release();
|
||||
if(withEventLoop)
|
||||
item.thread.events = new EventLoop();
|
||||
item.handle = createHandle(() -> {
|
||||
if(item.handle == null) {
|
||||
item.handle = currentHandle();
|
||||
}
|
||||
try {
|
||||
callb();
|
||||
if(withEventLoop)
|
||||
item.thread.events.loop();
|
||||
} catch(e) {
|
||||
dropThread(item);
|
||||
throw e;
|
||||
}
|
||||
dropThread(item);
|
||||
});
|
||||
return item.thread;
|
||||
}
|
||||
|
||||
public static function runWithEventLoop(job:()->Void):Void {
|
||||
var thread = current();
|
||||
if(thread.events == null) {
|
||||
thread.events = new EventLoop();
|
||||
try {
|
||||
job();
|
||||
thread.events.loop();
|
||||
thread.events = null;
|
||||
} catch(e) {
|
||||
thread.events = null;
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
job();
|
||||
}
|
||||
}
|
||||
|
||||
static function dropThread(deleteItem) {
|
||||
threadsMutex.acquire();
|
||||
for(i => item in threads) {
|
||||
if(item == deleteItem) {
|
||||
threads.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
threadsMutex.release();
|
||||
}
|
||||
|
||||
public function readMessage(block:Bool):Dynamic {
|
||||
return messages.pop(block);
|
||||
}
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function sendMessage(msg:Dynamic) {
|
||||
messages.add(msg);
|
||||
}
|
||||
}
|
58
Kha/Tools/macos/std/hl/_std/sys/thread/Tls.hx
Normal file
58
Kha/Tools/macos/std/hl/_std/sys/thread/Tls.hx
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package sys.thread;
|
||||
|
||||
#if doc_gen
|
||||
@:coreApi
|
||||
extern class Tls<T> {
|
||||
var value(get, set):T;
|
||||
function new():Void;
|
||||
}
|
||||
#else
|
||||
|
||||
@:hlNative("std")
|
||||
abstract Tls<T>(hl.Abstract<"hl_tls">) {
|
||||
public var value(get, set):T;
|
||||
|
||||
public function new() {
|
||||
this = tls_alloc(true);
|
||||
}
|
||||
|
||||
function get_value():T {
|
||||
return tls_get(this);
|
||||
}
|
||||
|
||||
function set_value(v:T) {
|
||||
tls_set(this, v);
|
||||
return v;
|
||||
}
|
||||
|
||||
static function tls_alloc(gcValue:Bool)
|
||||
return null;
|
||||
|
||||
static function tls_get(t):Dynamic
|
||||
return null;
|
||||
|
||||
static function tls_set(t, v:Dynamic) {}
|
||||
}
|
||||
#end
|
Reference in New Issue
Block a user