Update Files

This commit is contained in:
2025-01-22 16:18:30 +01:00
parent ed4603cf95
commit a36294b518
16718 changed files with 2960346 additions and 0 deletions

View File

@ -0,0 +1,128 @@
/*
* 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 Date {
private var mSeconds:Float;
public function new(year:Int, month:Int, day:Int, hour:Int, min:Int, sec:Int):Void {
mSeconds = untyped __global__.__hxcpp_new_date(year, month, day, hour, min, sec);
}
public function getTime():Float {
return mSeconds * 1000.0;
}
public function getHours():Int {
return untyped __global__.__hxcpp_get_hours(mSeconds);
}
public function getMinutes():Int {
return untyped __global__.__hxcpp_get_minutes(mSeconds);
}
public function getSeconds():Int {
return untyped __global__.__hxcpp_get_seconds(mSeconds);
}
public function getFullYear():Int {
return untyped __global__.__hxcpp_get_year(mSeconds);
}
public function getMonth():Int {
return untyped __global__.__hxcpp_get_month(mSeconds);
}
public function getDate():Int {
return untyped __global__.__hxcpp_get_date(mSeconds);
}
public function getDay():Int {
return untyped __global__.__hxcpp_get_day(mSeconds);
}
public function getUTCHours():Int {
return untyped __global__.__hxcpp_get_utc_hours(mSeconds);
}
public function getUTCMinutes():Int {
return untyped __global__.__hxcpp_get_utc_minutes(mSeconds);
}
public function getUTCSeconds():Int {
return untyped __global__.__hxcpp_get_utc_seconds(mSeconds);
}
public function getUTCFullYear():Int {
return untyped __global__.__hxcpp_get_utc_year(mSeconds);
}
public function getUTCMonth():Int {
return untyped __global__.__hxcpp_get_utc_month(mSeconds);
}
public function getUTCDate():Int {
return untyped __global__.__hxcpp_get_utc_date(mSeconds);
}
public function getUTCDay():Int {
return untyped __global__.__hxcpp_get_utc_day(mSeconds);
}
public function getTimezoneOffset():Int {
return -Std.int((untyped __global__.__hxcpp_timezone_offset(mSeconds)) / 60);
}
public function toString():String {
return untyped __global__.__hxcpp_to_string(mSeconds);
}
public static function now():Date {
return fromTime(untyped __global__.__hxcpp_date_now() * 1000.0);
}
private static function new1(t:Dynamic):Date {
return new Date(2005, 1, 1, 0, 0, 0);
}
public static function fromTime(t:Float):Date {
var result = new Date(0, 0, 0, 0, 0, 0);
result.mSeconds = t * 0.001;
return result;
}
public static function fromString(s:String):Date {
switch (s.length) {
case 8: // hh:mm:ss
var k = s.split(":");
return Date.fromTime(Std.parseInt(k[0]) * 3600000. + Std.parseInt(k[1]) * 60000. + Std.parseInt(k[2]) * 1000.);
case 10: // YYYY-MM-DD
var k = s.split("-");
return new Date(Std.parseInt(k[0]), Std.parseInt(k[1]) - 1, Std.parseInt(k[2]), 0, 0, 0);
case 19: // YYYY-MM-DD hh:mm:ss
var k = s.split(" ");
var y = k[0].split("-");
var t = k[1].split(":");
return new Date(Std.parseInt(y[0]), Std.parseInt(y[1]) - 1, Std.parseInt(y[2]), Std.parseInt(t[0]), Std.parseInt(t[1]), Std.parseInt(t[2]));
default:
throw "Invalid date format : " + s;
}
}
}

View File

@ -0,0 +1,193 @@
/*
* 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.
*/
@:buildXml('<include name="${HXCPP}/src/hx/libs/regexp/Build.xml"/>')
@:coreApi class EReg {
var r:Dynamic;
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 = _hx_regexp_new_options(r, opt);
}
public function match(s:String):Bool {
var p = _hx_regexp_match(r, s, 0, s.length);
if (p)
last = s;
else
last = null;
return p;
}
public function matched(n:Int):String {
var m = _hx_regexp_matched(r, n);
return m;
}
public function matchedLeft():String {
var p = _hx_regexp_matched_pos(r, 0);
return last.substr(0, p.pos);
}
public function matchedRight():String {
var p = _hx_regexp_matched_pos(r, 0);
var sz = p.pos + p.len;
return last.substr(sz, last.length - sz);
}
public function matchedPos():{pos:Int, len:Int} {
return _hx_regexp_matched_pos(r, 0);
}
public function matchSub(s:String, pos:Int, len:Int = -1):Bool {
var p = _hx_regexp_match(r, s, 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 (!_hx_regexp_match(r, s, pos, len))
break;
var p = _hx_regexp_matched_pos(r, 0);
if (p.len == 0 && !first) {
if (p.pos == s.length)
break;
p.pos += 1;
}
a.push(s.substr(pos, p.pos - pos));
var tot = p.pos + p.len - 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 (!_hx_regexp_match(r, s, pos, len))
break;
var p = _hx_regexp_matched_pos(r, 0);
if (p.len == 0 && !first) {
if (p.pos == s.length)
break;
p.pos += 1;
}
b.addSub(s, pos, p.pos - pos);
if (a.length > 0)
b.add(a[0]);
var i = 1;
while (i < a.length) {
var k = a[i];
var c = k.charCodeAt(0);
// 1...9
if (c >= 49 && c <= 57) {
var p = try _hx_regexp_matched_pos(r, Std.int(c) - 48) catch (e:String) null;
if (p == null) {
b.add("$");
b.add(k);
} else {
b.addSub(s, p.pos, p.len);
b.addSub(k, 1, k.length - 1);
}
} else if (c == null) {
b.add("$");
i++;
var k2 = a[i];
if (k2 != null && k2.length > 0)
b.add(k2);
} else
b.add("$" + k);
i++;
}
var tot = p.pos + p.len - 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 p = _hx_regexp_matched_pos(r, 0);
buf.add(s.substr(offset, p.pos - offset));
buf.add(f(this));
if (p.len == 0) {
buf.add(s.substr(p.pos, 1));
offset = p.pos + 1;
} else
offset = p.pos + p.len;
} 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;
function toString():String
return 'EReg($r)';
@:native("_hx_regexp_new_options")
extern static function _hx_regexp_new_options(s:String, options:String):Dynamic;
@:native("_hx_regexp_match")
extern static function _hx_regexp_match(handler:Dynamic, string:String, pos:Int, len:Int):Bool;
@:native("_hx_regexp_matched")
extern static function _hx_regexp_matched(handle:Dynamic, pos:Int):String;
@:native("_hx_regexp_matched_pos")
extern static function _hx_regexp_matched_pos(handle:Dynamic, match:Int):{pos:Int, len:Int};
}

View File

@ -0,0 +1,129 @@
/*
* 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 cpp.ObjectType;
@:coreApi
@:analyzer(ignore)
class Reflect {
public static function hasField(o:Dynamic, field:String):Bool
untyped {
return o != null && o.__HasField(field);
}
public static function field(o:Dynamic, field:String):Dynamic
untyped {
return (o == null) ? null : o.__Field(field, untyped __cpp__("::hx::paccNever"));
}
public static function setField(o:Dynamic, field:String, value:Dynamic):Void
untyped {
if (o != null)
o.__SetField(field, value, untyped __cpp__("::hx::paccNever"));
}
public static function getProperty(o:Dynamic, field:String):Dynamic {
return (o == null) ? null : o.__Field(field, untyped __cpp__("::hx::paccAlways"));
}
public static function setProperty(o:Dynamic, field:String, value:Dynamic):Void {
if (o != null)
o.__SetField(field, value, untyped __cpp__("::hx::paccAlways"));
}
public static function callMethod(o:Dynamic, func:haxe.Constraints.Function, args:Array<Dynamic>):Dynamic
untyped {
if (func != null && func.__GetType() == ObjectType.vtString) {
if (o == null)
throw cpp.ErrorConstants.invalidObject;
func = o.__Field(func, untyped __cpp__("::hx::paccDynamic"));
}
if (func == null)
throw cpp.ErrorConstants.nullFunctionPointer;
untyped func.__SetThis(o);
return untyped func.__Run(args);
}
public static function fields(o:Dynamic):Array<String>
untyped {
if (o == null)
return new Array();
var a:Array<String> = [];
o.__GetFields(a);
return a;
}
public static function isFunction(f:Dynamic):Bool
untyped {
return f != null && f.__GetType() == ObjectType.vtFunction;
}
public static function compare<T>(a:T, b:T):Int {
return (a == b) ? 0 : (((a : Dynamic) > (b : Dynamic)) ? 1 : -1);
}
public static function compareMethods(f1:Dynamic, f2:Dynamic):Bool {
if (f1 == f2)
return true;
if (!isFunction(f1) || !isFunction(f2))
return false;
return untyped __global__.__hxcpp_same_closure(f1, f2);
}
public static function isObject(v:Dynamic):Bool
untyped {
if (v == null)
return false;
var t:Int = v.__GetType();
return t == ObjectType.vtObject || t == ObjectType.vtClass || t == ObjectType.vtString || t == ObjectType.vtArray;
}
public static function isEnumValue(v:Dynamic):Bool
untyped {
return v != null && v.__GetType() == ObjectType.vtEnum;
}
public static function deleteField(o:Dynamic, field:String):Bool
untyped {
if (o == null)
return false;
return untyped __global__.__hxcpp_anon_remove(o, field);
}
public static function copy<T>(o:Null<T>):Null<T> {
if (o == null)
return null;
if (untyped o.__GetType() == ObjectType.vtString)
return o;
if (untyped o.__GetType() == ObjectType.vtArray)
return untyped o.__Field("copy", untyped __cpp__("::hx::paccDynamic"))();
var o2:Dynamic = {};
for (f in Reflect.fields(o))
Reflect.setField(o2, f, Reflect.field(o, f));
return o2;
}
@:overload(function(f:Array<Dynamic>->Void):Dynamic {})
public static function makeVarArgs(f:Array<Dynamic>->Dynamic):Dynamic {
return untyped __global__.__hxcpp_create_var_args(f);
}
}

View File

@ -0,0 +1,63 @@
/*
* 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.
*/
@:headerClassCode("\t\tstatic inline String string(String &s) { return s; }")
@:coreApi class Std {
@:deprecated('Std.is is deprecated. Use Std.isOfType instead.')
@:keep public static inline function is(v:Dynamic, t:Dynamic):Bool {
return isOfType(v, t);
}
public static function isOfType(v:Dynamic, t:Dynamic):Bool {
return untyped __global__.__instanceof(v, t);
}
@:keep public static function downcast<T:{}, S:T>(value:T, c:Class<S>):S {
return Std.isOfType(value, c) ? cast value : null;
}
@:deprecated('Std.instance() is deprecated. Use Std.downcast() instead.')
@:keep public static function instance<T:{}, S:T>(value:T, c:Class<S>):S {
return inline downcast(value, c);
}
@:keep public static function string(s:Dynamic):String {
return untyped s == null ? "null" : s.toString();
}
@:keep public static function int(x:Float):Int {
return untyped __global__.__int__(x);
}
@:keep public static function parseInt(x:String):Null<Int> {
return untyped __global__.__hxcpp_parse_int(x);
}
@:keep public static function parseFloat(x:String):Float {
return untyped __global__.__hxcpp_parse_float(x);
}
@:keep public static function random(x:Int):Int {
if (x <= 0)
return 0;
return untyped __global__.__hxcpp_irand(x);
}
}

View File

@ -0,0 +1,101 @@
/*
* 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 cpp.NativeString;
using cpp.NativeArray;
@:coreApi
class StringBuf {
private var b:Array<String>;
public var length(get, never):Int;
var charBuf:Array<cpp.Char>;
public function new():Void {}
private function charBufAsString():String {
var len = charBuf.length;
charBuf.push(0);
return NativeString.fromGcPointer(charBuf.address(0), len);
}
private function flush():Void {
if (b == null)
b = [charBufAsString()];
else
b.push(charBufAsString());
charBuf = null;
}
function get_length():Int {
var len = 0;
if (charBuf != null)
len = charBuf.length;
if (b != null)
for (s in b)
len += s == null ? 4 : s.length;
return len;
}
public inline function add<T>(x:T):Void {
if (charBuf != null)
flush();
if (b == null)
b = [Std.string(x)];
else
b.push(Std.string(x));
}
public #if !cppia inline #end function addSub(s:String, pos:Int, ?len:Int):Void {
if (charBuf != null)
flush();
if (b == null)
b = [s.substr(pos, len)];
else
b.push(s.substr(pos, len));
}
public #if !cppia inline #end function addChar(c:Int):Void {
#if hxcpp_smart_strings
if (c >= 127)
add(String.fromCharCode(c));
else
#end
{
if (charBuf == null)
charBuf = new Array<cpp.Char>();
charBuf.push(c);
}
}
public function toString():String {
if (charBuf != null)
flush();
if (b == null || b.length == 0)
return "";
if (b.length == 1)
return b[0];
return b.join("");
}
}

View File

@ -0,0 +1,138 @@
/*
* 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 cpp.NativeSys;
import haxe.SysTools;
@:coreApi class Sys {
public static function print(v:Dynamic):Void {
untyped __global__.__hxcpp_print(v);
}
public static function println(v:Dynamic):Void {
untyped __global__.__hxcpp_println(v);
}
@:access(sys.io.FileInput)
public static function stdin():haxe.io.Input {
return new sys.io.FileInput(cpp.NativeFile.file_stdin());
}
@:access(sys.io.FileOutput)
public static function stdout():haxe.io.Output {
return new sys.io.FileOutput(cpp.NativeFile.file_stdout());
}
@:access(sys.io.FileOutput)
public static function stderr():haxe.io.Output {
return new sys.io.FileOutput(cpp.NativeFile.file_stderr());
}
public static function getChar(echo:Bool):Int {
return NativeSys.sys_getch(echo);
}
public static function args():Array<String>
untyped {
return __global__.__get_args();
}
public static function getEnv(s:String):String {
var v = NativeSys.get_env(s);
if (v == null)
return null;
return v;
}
public static function putEnv(s:String, v:String):Void {
NativeSys.put_env(s, v);
}
public static function sleep(seconds:Float):Void {
NativeSys.sys_sleep(seconds);
}
public static function setTimeLocale(loc:String):Bool {
return NativeSys.set_time_locale(loc);
}
public static function getCwd():String {
return NativeSys.get_cwd();
}
public static function setCwd(s:String):Void {
NativeSys.set_cwd(s);
}
public static function systemName():String {
return NativeSys.sys_string();
}
public static function command(cmd:String, ?args:Array<String>):Int {
if (args == null) {
return NativeSys.sys_command(cmd);
} else {
switch (systemName()) {
case "Windows":
cmd = [
for (a in [StringTools.replace(cmd, "/", "\\")].concat(args))
SysTools.quoteWinArg(a, true)
].join(" ");
return NativeSys.sys_command(cmd);
case _:
cmd = [cmd].concat(args).map(SysTools.quoteUnixArg).join(" ");
return NativeSys.sys_command(cmd);
}
}
}
public static function exit(code:Int):Void {
untyped __global__.__hxcpp_exit(code);
}
public static function time():Float {
return NativeSys.sys_time();
}
public static function cpuTime():Float {
return NativeSys.sys_cpu_time();
}
@:deprecated("Use programPath instead") public static function executablePath():String {
return NativeSys.sys_exe_path();
}
public static function programPath():String {
return NativeSys.sys_exe_path();
}
public static function environment():Map<String, String> {
var vars:Array<String> = NativeSys.sys_env();
var result = new haxe.ds.StringMap<String>();
var i = 0;
while (i < vars.length) {
result.set(vars[i], vars[i + 1]);
i += 2;
}
return result;
}
}

View 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.
*/
enum ValueType {
TNull;
TInt;
TFloat;
TBool;
TObject;
TFunction;
TClass(c:Class<Dynamic>);
TEnum(e:Enum<Dynamic>);
TUnknown;
}
@:coreApi class Type {
public static function getClass<T>(o:T):Class<T>
untyped {
if (o == null || !Reflect.isObject(o))
return null;
var c = o.__GetClass();
switch (c.toString()) {
case "__Anon":
return null;
case "Class":
return null;
}
return c;
}
public static function getEnum(o:EnumValue):Enum<Dynamic>
untyped {
if (o == null)
return null;
return untyped o.__GetClass();
}
public static function getSuperClass(c:Class<Dynamic>):Class<Dynamic>
untyped {
return c.GetSuper();
}
public static function getClassName(c:Class<Dynamic>):String {
if (c == null)
return null;
return untyped c.mName;
}
public static function getEnumName(e:Enum<Dynamic>):String {
return untyped e.__ToString();
}
public static function resolveClass(name:String):Class<Dynamic>
untyped {
var result:Class<Dynamic> = Class.Resolve(name);
if (result != null && result.__IsEnum())
return null;
return result;
}
public static function resolveEnum(name:String):Enum<Dynamic>
untyped {
var result:Class<Dynamic> = Class.Resolve(name);
if (result != null && !result.__IsEnum())
return null;
return result;
}
public static function createInstance<T>(cl:Class<T>, args:Array<Dynamic>):T
untyped {
if (cl != null)
return cl.ConstructArgs(args);
return null;
}
public static function createEmptyInstance<T>(cl:Class<T>):T
untyped {
return cl.ConstructEmpty();
}
public static function createEnum<T>(e:Enum<T>, constr:String, ?params:Array<Dynamic>):T {
return untyped e.ConstructEnum(constr, params);
}
public static function createEnumIndex<T>(e:Enum<T>, index:Int, ?params:Array<Dynamic>):T {
var c = Type.getEnumConstructs(e)[index];
if (c == null)
throw index + " is not a valid enum constructor index";
return createEnum(e, c, params);
}
public static function getInstanceFields(c:Class<Dynamic>):Array<String> {
return untyped c.GetInstanceFields();
}
public static function getClassFields(c:Class<Dynamic>):Array<String> {
return untyped c.GetClassFields();
}
public static function getEnumConstructs(e:Enum<Dynamic>):Array<String>
untyped {
return untyped e.GetClassFields();
}
public static function typeof(v:Dynamic):ValueType
untyped {
if (v == null)
return TNull;
var t:Int = untyped v.__GetType();
switch (t) {
case 2:
return TBool;
case 0xFF:
return TInt;
case 1:
return TFloat;
case 6:
return TFunction;
case 4:
return TObject;
case 7:
return TEnum(v.__GetClass());
default:
return untyped TClass(v.__GetClass());
}
}
@:native("__hxcpp_enum_eq")
extern private static function nativeEnumEq(a:Dynamic, b:Dynamic):Bool;
#if !cppia inline #end
public static function enumEq<T>(a:T, b:T):Bool
return nativeEnumEq(a,b);
public static function enumConstructor(e:EnumValue):String {
var value:cpp.EnumBase = cast e;
return value._hx_getTag();
}
public static function enumParameters(e:EnumValue):Array<Dynamic> {
var value:cpp.EnumBase = cast e;
return value._hx_getParameters();
}
@:native("_hx_getEnumValueIndex")
extern private static function getEnumValueIndex(e:EnumValue):Int;
#if !cppia inline #end public static function enumIndex(e:EnumValue):Int {
return getEnumValueIndex(e);
}
public static function allEnums<T>(e:Enum<T>):Array<T> {
var names:Array<String> = untyped e.GetClassFields();
var enums = new Array<T>();
for (name in names) {
try {
var result:T = untyped e.ConstructEnum(name, null);
if (result != null)
enums.push(result);
} catch (invalidArgCount:String) {}
}
return enums;
}
}

View File

@ -0,0 +1,85 @@
package haxe;
//TODO: extend ::std::exception
@: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:Array<String>;
@: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;
}
}
}

View File

@ -0,0 +1,418 @@
/*
* 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;
import haxe.Int64Helper;
@:notNull
@:include("cpp/Int64.h")
@:native("cpp::Int64Struct")
private extern class ___Int64 {
@:native("_hx_int64_make")
static function make(high:Int32, low:Int32):__Int64;
@:native(" ::cpp::Int64Struct")
static function ofInt(value:Int):__Int64;
@:native(" ::cpp::Int64Struct::is")
static function isInt64(d:Dynamic):Bool;
@:native("_hx_int64_is_neg")
static function isNeg(a:__Int64):Bool;
@:native("_hx_int64_is_zero")
static function isZero(a:__Int64):Bool;
@:native("_hx_int64_compare")
static function compare(a:__Int64, b:__Int64):Int;
@:native("_hx_int64_ucompare")
static function ucompare(a:__Int64, b:__Int64):Int;
@:native("_hx_int64_to_string")
static function toString(a:__Int64):String;
@:native("_hx_int64_neg")
static function neg(a:__Int64):__Int64;
@:native("_hx_int64_pre_increment")
static function preIncrement(a:__Int64):__Int64;
@:native("_hx_int64_post_increment")
static function postIncrement(a:__Int64):__Int64;
@:native("_hx_int64_pre_decrement")
static function preDecrement(a:__Int64):__Int64;
@:native("_hx_int64_post_decrement")
static function postDecrement(a:__Int64):__Int64;
@:native("_hx_int64_add")
static function add(a:__Int64, b:__Int64):__Int64;
@:native("_hx_int64_add")
static function addInt(a:__Int64, b:Int):__Int64;
@:native("_hx_int64_sub")
static function sub(a:__Int64, b:__Int64):__Int64;
@:native("_hx_int64_sub")
static function subInt(a:__Int64, b:Int):__Int64;
@:native("_hx_int64_sub")
static function intSub(a:Int, b:__Int64):__Int64;
@:native("_hx_int64_mul")
static function mul(a:__Int64, b:__Int64):__Int64;
@:native("_hx_int64_div")
static function div(a:__Int64, b:__Int64):__Int64;
@:native("_hx_int64_mod")
static function mod(a:__Int64, b:__Int64):__Int64;
@:native("_hx_int64_eq")
static function eq(a:__Int64, b:__Int64):Bool;
@:native("_hx_int64_eq")
static function eqInt(a:__Int64, b:Int):Bool;
@:native("_hx_int64_neq")
static function neq(a:__Int64, b:__Int64):Bool;
@:native("_hx_int64_neq")
static function neqInt(a:__Int64, b:Int):Bool;
@:native("_hx_int64_complement")
static function complement(a:__Int64):__Int64;
@:native("_hx_int64_and")
static function bitAnd(a:__Int64, b:__Int64):__Int64;
@:native("_hx_int64_or")
static function bitOr(a:__Int64, b:__Int64):__Int64;
@:native("_hx_int64_xor")
static function bitXor(a:__Int64, b:__Int64):__Int64;
@:native("_hx_int64_shl")
static function shl(a:__Int64, b:Int):__Int64;
@:native("_hx_int64_shr")
static function shr(a:__Int64, b:Int):__Int64;
@:native("_hx_int64_ushr")
static function ushr(a:__Int64, b:Int):__Int64;
@:native("_hx_int64_high")
static function high(a:__Int64):Int32;
@:native("_hx_int64_low")
static function low(a:__Int64):Int32;
}
private typedef __Int64 = ___Int64;
@:coreApi
@:transitive
abstract Int64(__Int64) from __Int64 to __Int64 {
public #if !cppia inline #end function copy():Int64
return this;
public static #if !cppia inline #end function make(high:Int32, low:Int32):Int64 {
return __Int64.make(high, low);
}
@:from
public static #if !cppia inline #end function ofInt(x:Int):Int64 {
return __Int64.ofInt(x);
}
public static #if !cppia inline #end function toInt(x:Int64):Int {
if (x.high != x.low >> 31)
throw "Overflow";
return x.low;
}
@:deprecated('haxe.Int64.is() is deprecated. Use haxe.Int64.isInt64() instead')
inline public static function is(val:Dynamic):Bool {
return isInt64(val);
}
public static #if !cppia inline #end function isInt64(val:Dynamic):Bool
return __Int64.isInt64(val);
@:deprecated("Use high instead")
public static #if !cppia inline #end function getHigh(x:Int64):Int32
return x.high;
@:deprecated("Use low instead")
public static #if !cppia inline #end function getLow(x:Int64):Int32
return x.low;
public static #if !cppia inline #end function isNeg(x:Int64):Bool
return __Int64.isNeg(x);
public static #if !cppia inline #end function isZero(x:Int64):Bool
return __Int64.isZero(x);
public static #if !cppia inline #end function compare(a:Int64, b:Int64):Int
return __Int64.compare(a, b);
public static #if !cppia inline #end function ucompare(a:Int64, b:Int64):Int
return __Int64.ucompare(a, b);
public static #if !cppia inline #end function toStr(x:Int64):String
return x.toString();
private #if !cppia inline #end function toString():String
return __Int64.toString(this);
public static function parseString(sParam:String):Int64 {
return Int64Helper.parseString(sParam);
}
public static function fromFloat(f:Float):Int64 {
return Int64Helper.fromFloat(f);
}
public static function divMod(dividend:Int64, divisor:Int64):{quotient:Int64, modulus:Int64} {
var q = dividend / divisor;
if (isZero(divisor))
throw "divide by zero";
var m = dividend - q * divisor;
return {quotient: q, modulus: m};
}
@:op(-A)
public static #if !cppia inline #end function neg(x:Int64):Int64
return __Int64.neg(x);
@:op(++A) private inline function preIncrement():Int64 {
#if cppia
this = this + make(0, 1);
return this;
#else
return __Int64.preIncrement(this);
#end
}
@:op(A++) private inline function postIncrement():Int64 {
#if cppia
var result = this;
this = this + make(0, 1);
return result;
#else
return __Int64.postIncrement(this);
#end
}
@:op(--A) private inline function preDecrement():Int64 {
#if cppia
untyped this = this - make(0, 1);
return this;
#else
return __Int64.preDecrement(this);
#end
}
@:op(A--) private inline function postDecrement():Int64 {
#if cppia
var result = this;
this = this - make(0, 1);
return result;
#else
return __Int64.postDecrement(this);
#end
}
@:op(A + B)
public static #if !cppia inline #end function add(a:Int64, b:Int64):Int64
return __Int64.add(a, b);
@:op(A + B)
@:commutative
private static #if !cppia inline #end function addInt(a:Int64, b:Int):Int64
return __Int64.addInt(a, b);
@:op(A - B)
public static #if !cppia inline #end function sub(a:Int64, b:Int64):Int64 {
return __Int64.sub(a, b);
}
@:op(A - B)
private static #if !cppia inline #end function subInt(a:Int64, b:Int):Int64
return __Int64.subInt(a, b);
@:op(A - B)
private static #if !cppia inline #end function intSub(a:Int, b:Int64):Int64
return __Int64.intSub(a, b);
@:op(A * B)
public static #if !cppia inline #end function mul(a:Int64, b:Int64):Int64
return __Int64.mul(a, b);
@:op(A * B)
@:commutative
private static #if !cppia inline #end function mulInt(a:Int64, b:Int):Int64
return mul(a, b);
@:op(A / B)
public static #if !cppia inline #end function div(a:Int64, b:Int64):Int64 {
if (__Int64.isZero(b))
throw "divide by zero";
return __Int64.div(a, b);
}
@:op(A / B)
private static #if !cppia inline #end function divInt(a:Int64, b:Int):Int64
return div(a, b);
@:op(A / B)
private static #if !cppia inline #end function intDiv(a:Int, b:Int64):Int64
return toInt(div(a, b));
@:op(A % B)
public static #if !cppia inline #end function mod(a:Int64, b:Int64):Int64 {
if (__Int64.isZero(b))
throw "divide by zero";
return __Int64.mod(a, b);
}
@:op(A % B)
private static #if !cppia inline #end function modInt(a:Int64, b:Int):Int64
return toInt(mod(a, b));
@:op(A % B)
private static #if !cppia inline #end function intMod(a:Int, b:Int64):Int64
return toInt(mod(a, b));
@:op(A == B)
public static #if !cppia inline #end function eq(a:Int64, b:Int64):Bool
return __Int64.eq(a, b);
@:op(A == B)
@:commutative
private static #if !cppia inline #end function eqInt(a:Int64, b:Int):Bool
return __Int64.eqInt(a, b);
@:op(A != B)
public static #if !cppia inline #end function neq(a:Int64, b:Int64):Bool
return __Int64.neq(a, b);
@:op(A != B)
@:commutative
private static #if !cppia inline #end function neqInt(a:Int64, b:Int):Bool
return neq(a, b);
@:op(A < B)
private static #if !cppia inline #end function lt(a:Int64, b:Int64):Bool
return compare(a, b) < 0;
@:op(A < B)
private static #if !cppia inline #end function ltInt(a:Int64, b:Int):Bool
return lt(a, b);
@:op(A < B)
private static #if !cppia inline #end function intLt(a:Int, b:Int64):Bool
return lt(a, b);
@:op(A <= B)
private static #if !cppia inline #end function lte(a:Int64, b:Int64):Bool
return compare(a, b) <= 0;
@:op(A <= B)
private static #if !cppia inline #end function lteInt(a:Int64, b:Int):Bool
return lte(a, b);
@:op(A <= B)
private static #if !cppia inline #end function intLte(a:Int, b:Int64):Bool
return lte(a, b);
@:op(A > B)
private static #if !cppia inline #end function gt(a:Int64, b:Int64):Bool
return compare(a, b) > 0;
@:op(A > B)
private static #if !cppia inline #end function gtInt(a:Int64, b:Int):Bool
return gt(a, b);
@:op(A > B)
private static #if !cppia inline #end function intGt(a:Int, b:Int64):Bool
return gt(a, b);
@:op(A >= B)
private static #if !cppia inline #end function gte(a:Int64, b:Int64):Bool
return compare(a, b) >= 0;
@:op(A >= B)
private static #if !cppia inline #end function gteInt(a:Int64, b:Int):Bool
return gte(a, b);
@:op(A >= B)
private static #if !cppia inline #end function intGte(a:Int, b:Int64):Bool
return gte(a, b);
@:op(~A)
private static #if !cppia inline #end function complement(a:Int64):Int64
return __Int64.complement(a);
@:op(A & B)
public static #if !cppia inline #end function and(a:Int64, b:Int64):Int64
return __Int64.bitAnd(a, b);
@:op(A | B)
public static #if !cppia inline #end function or(a:Int64, b:Int64):Int64
return __Int64.bitOr(a, b);
@:op(A ^ B)
public static #if !cppia inline #end function xor(a:Int64, b:Int64):Int64
return __Int64.bitXor(a, b);
@:op(A << B)
public static #if !cppia inline #end function shl(a:Int64, b:Int):Int64
return __Int64.shl(a, b);
@:op(A >> B)
public static #if !cppia inline #end function shr(a:Int64, b:Int):Int64
return __Int64.shr(a, b);
@:op(A >>> B)
public static #if !cppia inline #end function ushr(a:Int64, b:Int):Int64
return __Int64.ushr(a, b);
public var high(get, never):Int32;
private #if !cppia inline #end function get_high():Int32
return __Int64.high(this);
public var low(get, never):Int32;
private #if !cppia inline #end function get_low():Int32
return __Int64.low(this);
}

View File

@ -0,0 +1,49 @@
/*
* 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;
@:coreApi class Log {
@:native("__trace")
extern private static function nativeTrace(message:String, posInfo:Dynamic):Void;
public static dynamic function trace(v:Dynamic, ?infos:PosInfos):Void {
if (infos != null && infos.customParams != null) {
var extra:String = "";
for (v in infos.customParams)
extra += "," + v;
nativeTrace(v + extra, infos);
} else
nativeTrace(v, infos);
}
public static function formatOutput(v:Dynamic, infos:PosInfos):String {
var str = Std.string(v);
if (infos == null)
return str;
var pstr = infos.fileName + ":" + infos.lineNumber;
if (infos != null && infos.customParams != null)
for (v in infos.customParams)
str += ", " + Std.string(v);
return pstr + ": " + str;
}
}

View File

@ -0,0 +1,42 @@
package haxe;
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 {
}
@:noDebug //Do not mess up the exception stack
static public function callStack():Array<String> {
return untyped __global__.__hxcpp_get_call_stack(true);
}
@:noDebug //Do not mess up the exception stack/
static public function exceptionStack():Array<String> {
return untyped __global__.__hxcpp_get_exception_stack();
}
static public function toHaxe(native:Array<String>, skip:Int = 0):Array<StackItem> {
var stack:Array<String> = native;
var m = new Array<StackItem>();
for (i in 0...stack.length) {
if(skip > i) {
continue;
}
var words = stack[i].split("::");
if (words.length == 0)
m.push(CFunction)
else if (words.length == 2)
m.push(Method(words[0], words[1]));
else if (words.length == 4)
m.push(FilePos(Method(words[0], words[1]), words[2], Std.parseInt(words[3])));
}
return m;
}
}

View File

@ -0,0 +1,41 @@
/*
* 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;
@:coreApi
class Resource {
public static function listNames():Array<String> {
return untyped __global__.__hxcpp_resource_names();
}
public static function getString(name:String):String {
return untyped __global__.__hxcpp_resource_string(name);
}
public static function getBytes(name:String):haxe.io.Bytes {
var array:haxe.io.BytesData = untyped __global__.__hxcpp_resource_bytes(name);
if (array == null)
return null;
return haxe.io.Bytes.ofData(array);
}
}

View File

@ -0,0 +1,85 @@
/*
* 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;
using cpp.NativeString;
@:coreApi
@:deprecated('haxe.Utf8 is deprecated. Use UnicodeString instead.')
class Utf8 {
var __s:Array<Int>;
public function new(?size:Int):Void {
__s = new Array<Int>();
if (size != null && size > 0)
cpp.NativeArray.reserve(__s, size);
}
public function addChar(c:Int):Void {
__s.push(c);
}
public function toString():String {
return untyped __global__.__hxcpp_char_array_to_utf8_string(__s);
}
// Incoming string is array of bytes containing possibly invalid utf8 chars
// Result is the same string with the bytes expanded into utf8 sequences
public static function encode(s:String):String {
return untyped __global__.__hxcpp_char_bytes_to_utf8_string(s);
}
// Incoming string is array of bytes representing valid utf8 chars
// Result is a string containing the compressed bytes
public static function decode(s:String):String {
return untyped __global__.__hxcpp_utf8_string_to_char_bytes(s);
}
public #if !cppia inline #end static function iter(s:String, chars:Int->Void):Void {
var src = s.c_str();
var end = src.add(s.length);
while (src.lt(end))
chars(src.ptr.utf8DecodeAdvance());
}
public static function charCodeAt(s:String, index:Int):Int {
return s.utf8CharCodeAt(index);
}
public static function validate(s:String):Bool {
return s.utf8IsValid();
}
public static function length(s:String):Int {
return s.utf8Length();
}
public static function compare(a:String, b:String):Int {
return a.compare(b);
}
public static function sub(s:String, pos:Int, len:Int):String {
return s.utf8Sub(pos, len);
}
}

View 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.
*/
package haxe.ds;
@:headerClassCode("
inline void set(int key, ::null value) { __int_hash_set(HX_MAP_THIS,key,value); }
inline void set(int key, bool value) { __int_hash_set(HX_MAP_THIS,key,value); }
inline void set(int key, char value) { __int_hash_set_int(HX_MAP_THIS,key,value); }
inline void set(int key, unsigned char value) { __int_hash_set_int(HX_MAP_THIS,key,value); }
inline void set(int key, signed char value) { __int_hash_set_int(HX_MAP_THIS,key,value); }
inline void set(int key, short value) { __int_hash_set_int(HX_MAP_THIS,key,value); }
inline void set(int key, unsigned short value) { __int_hash_set_int(HX_MAP_THIS,key,value); }
inline void set(int key, int value) { __int_hash_set_int(HX_MAP_THIS,key,value); }
inline void set(int key, unsigned int value) { __int_hash_set_int(HX_MAP_THIS,key,value); }
inline void set(int key, float value) { __int_hash_set_float(HX_MAP_THIS,key,value); }
inline void set(int key, double value) { __int_hash_set_float(HX_MAP_THIS,key,value); }
inline void set(int key, ::String value) { __int_hash_set_string(HX_MAP_THIS,key,value); }
template<typename V, typename H>
inline void set(int key, const ::cpp::Struct<V,H> &value) {__int_hash_set(HX_MAP_THIS,key,value); }
template<typename F>
inline void set(int key, const ::cpp::Function<F> &value) {__int_hash_set(HX_MAP_THIS,key,value); }
template<typename V>
inline void set(int key, const ::cpp::Pointer<V> &value) {__int_hash_set(HX_MAP_THIS,key,(Dynamic)value ); }
template<typename VALUE>
inline void set(Dynamic &key, const VALUE &value) { set( (int)key, value ); }
inline bool get_bool(int key) { return __int_hash_get_bool(h,key); }
inline int get_int(int key) { return __int_hash_get_int(h,key); }
inline Float get_float(int key) { return __int_hash_get_float(h,key); }
inline String get_string(int key) { return __int_hash_get_string(h,key); }
")
@:coreApi class IntMap<T> implements haxe.Constraints.IMap<Int, T> {
@:ifFeature("haxe.ds.IntMap.*")
private var h:Dynamic;
public function new():Void {}
public function set(key:Int, value:T):Void {
untyped __global__.__int_hash_set(__cpp__("HX_MAP_THIS"), key, value);
}
public function get(key:Int):Null<T> {
return untyped __global__.__int_hash_get(h, key);
}
public function exists(key:Int):Bool {
return untyped __global__.__int_hash_exists(h, key);
}
public function remove(key:Int):Bool {
return untyped __global__.__int_hash_remove(h, key);
}
public function keys():Iterator<Int> {
var a:Array<Int> = untyped __global__.__int_hash_keys(h);
return a.iterator();
}
public function iterator():Iterator<T> {
var a:Array<Dynamic> = untyped __global__.__int_hash_values(h);
return a.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 {
return untyped __global__.__int_hash_to_string(h);
}
public function clear():Void {
#if (hxcpp_api_level >= 400)
return untyped __global__.__int_hash_clear(h);
#else
h = null;
#end
}
#if (scriptable)
private function setString(key:Int, val:String):Void {
untyped __int_hash_set_string(__cpp__("HX_MAP_THIS"), key, val);
}
private function setInt(key:Int, val:Int):Void {
untyped __int_hash_set_int(__cpp__("HX_MAP_THIS"), key, val);
}
private function setBool(key:Int, val:Bool):Void {
untyped __int_hash_set_int(__cpp__("HX_MAP_THIS"), key, val);
}
private function setFloat(key:Int, val:Float):Void {
untyped __int_hash_set_float(__cpp__("HX_MAP_THIS"), key, val);
}
private function getString(key:Int):String {
return untyped __int_hash_get_string(h, key);
}
private function getInt(key:Int):Int {
return untyped __int_hash_get_int(h, key);
}
private function getBool(key:Int):Bool {
return untyped __int_hash_get_bool(h, key);
}
private function getFloat(key:Int):Float {
return untyped __int_hash_get_float(h, key);
}
#end
}

View 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.
*/
package haxe.ds;
@:headerClassCode("
inline void set(Dynamic key, ::null value) { __object_hash_set(HX_MAP_THIS,key,value); }
inline void set(Dynamic key, bool value) { __object_hash_set(HX_MAP_THIS,key,value); }
inline void set(Dynamic key, char value) { __object_hash_set_int(HX_MAP_THIS,key,value); }
inline void set(Dynamic key, unsigned char value) { __object_hash_set_int(HX_MAP_THIS,key,value); }
inline void set(Dynamic key, signed char value) { __object_hash_set_int(HX_MAP_THIS,key,value); }
inline void set(Dynamic key, short value) { __object_hash_set_int(HX_MAP_THIS,key,value); }
inline void set(Dynamic key, unsigned short value) { __object_hash_set_int(HX_MAP_THIS,key,value); }
inline void set(Dynamic key, int value) { __object_hash_set_int(HX_MAP_THIS,key,value); }
inline void set(Dynamic key, unsigned int value) { __object_hash_set_int(HX_MAP_THIS,key,value); }
inline void set(Dynamic key, float value) { __object_hash_set_float(HX_MAP_THIS,key,value); }
inline void set(Dynamic key, double value) { __object_hash_set_float(HX_MAP_THIS,key,value); }
inline void set(Dynamic key, ::String value) { __object_hash_set_string(HX_MAP_THIS,key,value); }
template<typename V, typename H>
inline void set(Dynamic key, const ::cpp::Struct<V,H> &value) {__object_hash_set(HX_MAP_THIS,key,value); }
template<typename V>
inline void set(Dynamic key, const ::cpp::Function<V> &value) {__object_hash_set(HX_MAP_THIS,key,(Dynamic)value ); }
template<typename V>
inline void set(Dynamic key, const ::cpp::Pointer<V> &value) {__object_hash_set(HX_MAP_THIS,key,(Dynamic)value ); }
inline bool get_bool(Dynamic key) { return __object_hash_get_bool(h,key); }
inline int get_int(Dynamic key) { return __object_hash_get_int(h,key); }
inline Float get_float(Dynamic key) { return __object_hash_get_float(h,key); }
inline String get_string(Dynamic key) { return __object_hash_get_string(h,key); }
")
@:coreApi
class ObjectMap<K:{}, V> implements haxe.Constraints.IMap<K, V> {
@:ifFeature("haxe.ds.ObjectMap.*")
private var h:Dynamic;
public function new():Void {}
public function set(key:K, value:V):Void {
untyped __global__.__object_hash_set(__cpp__("HX_MAP_THIS"), key, value);
}
public function get(key:K):Null<V> {
return untyped __global__.__object_hash_get(h, key);
}
public function exists(key:K):Bool {
return untyped __global__.__object_hash_exists(h, key);
}
public function remove(key:K):Bool {
return untyped __global__.__object_hash_remove(h, key);
}
public function keys():Iterator<K> {
var a:Array<K> = untyped __global__.__object_hash_keys(h);
return a.iterator();
}
public function iterator():Iterator<V> {
var a:Array<Dynamic> = untyped __global__.__object_hash_values(h);
return a.iterator();
}
@:runtime public inline function keyValueIterator():KeyValueIterator<K, V> {
return new haxe.iterators.MapKeyValueIterator(this);
}
public function copy():ObjectMap<K, V> {
var copied = new ObjectMap();
for (key in keys())
copied.set(key, get(key));
return copied;
}
public function toString():String {
return untyped __global__.__object_hash_to_string(h);
}
public function clear():Void {
#if (hxcpp_api_level >= 400)
return untyped __global__.__object_hash_clear(h);
#else
h = null;
#end
}
#if (scriptable)
private function setString(key:Dynamic, val:String):Void {
untyped __object_hash_set_string(__cpp__("HX_MAP_THIS"), key, val);
}
private function setInt(key:Dynamic, val:Int):Void {
untyped __object_hash_set_int(__cpp__("HX_MAP_THIS"), key, val);
}
private function setBool(key:Dynamic, val:Bool):Void {
untyped __object_hash_set_int(__cpp__("HX_MAP_THIS"), key, val);
}
private function setFloat(key:Dynamic, val:Float):Void {
untyped __object_hash_set_float(__cpp__("HX_MAP_THIS"), key, val);
}
private function getString(key:Dynamic):String {
return untyped __object_hash_get_string(h, key);
}
private function getInt(key:Dynamic):Int {
return untyped __object_hash_get_int(h, key);
}
private function getBool(key:Dynamic):Bool {
return untyped __object_hash_get_bool(h, key);
}
private function getFloat(key:Dynamic):Float {
return untyped __object_hash_get_float(h, key);
}
#end
}

View 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.
*/
package haxe.ds;
@:headerClassCode("
inline void set(String key, ::null value) { __string_hash_set(HX_MAP_THIS,key,value); }
inline void set(String key, bool value) { __string_hash_set(HX_MAP_THIS,key,value); }
inline void set(String key, char value) { __string_hash_set_int(HX_MAP_THIS,key,value); }
inline void set(String key, unsigned char value) { __string_hash_set_int(HX_MAP_THIS,key,value); }
inline void set(String key, signed char value) { __string_hash_set_int(HX_MAP_THIS,key,value); }
inline void set(String key, short value) { __string_hash_set_int(HX_MAP_THIS,key,value); }
inline void set(String key, unsigned short value) { __string_hash_set_int(HX_MAP_THIS,key,value); }
inline void set(String key, int value) { __string_hash_set_int(HX_MAP_THIS,key,value); }
inline void set(String key, unsigned int value) { __string_hash_set_int(HX_MAP_THIS,key,value); }
inline void set(String key, float value) { __string_hash_set_float(HX_MAP_THIS,key,value); }
inline void set(String key, double value) { __string_hash_set_float(HX_MAP_THIS,key,value); }
inline void set(String key, ::String value) { __string_hash_set_string(HX_MAP_THIS,key,value); }
template<typename V, typename H>
inline void set(String key, const ::cpp::Struct<V,H> &value) {__string_hash_set(HX_MAP_THIS,key,value); }
template<typename V>
inline void set(String key, const ::cpp::Function<V> &value) {__string_hash_set(HX_MAP_THIS,key,(Dynamic)value ); }
template<typename V>
inline void set(String key, const ::cpp::Pointer<V> &value) {__string_hash_set(HX_MAP_THIS,key,(Dynamic)value ); }
template<typename VALUE>
inline void set(Dynamic &key, const VALUE &value) { set( (String)key, value ); }
inline bool get_bool(String key) { return __string_hash_get_bool(h,key); }
inline int get_int(String key) { return __string_hash_get_int(h,key); }
inline Float get_float(String key) { return __string_hash_get_float(h,key); }
inline String get_string(String key) { return __string_hash_get_string(h,key); }
")
@:coreApi class StringMap<T> implements haxe.Constraints.IMap<String, T> {
@:ifFeature("haxe.ds.StringMap.*")
private var h:Dynamic;
public function new():Void {}
public function set(key:String, value:T):Void {
untyped __global__.__string_hash_set(__cpp__("HX_MAP_THIS"), key, value);
}
public function get(key:String):Null<T> {
return untyped __global__.__string_hash_get(h, key);
}
public function exists(key:String):Bool {
return untyped __global__.__string_hash_exists(h, key);
}
public function remove(key:String):Bool {
return untyped __global__.__string_hash_remove(h, key);
}
public function keys():Iterator<String> {
var a:Array<String> = untyped __global__.__string_hash_keys(h);
return a.iterator();
}
public function iterator():Iterator<T> {
var a:Array<Dynamic> = untyped __global__.__string_hash_values(h);
return a.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 {
return untyped __global__.__string_hash_to_string(h);
}
public function clear():Void {
#if (hxcpp_api_level >= 400)
return untyped __global__.__string_hash_clear(h);
#else
h = null;
#end
}
#if (scriptable)
private function setString(key:String, val:String):Void {
untyped __string_hash_set_string(__cpp__("HX_MAP_THIS"), key, val);
}
private function setInt(key:String, val:Int):Void {
untyped __string_hash_set_int(__cpp__("HX_MAP_THIS"), key, val);
}
private function setBool(key:String, val:Bool):Void {
untyped __string_hash_set_int(__cpp__("HX_MAP_THIS"), key, val);
}
private function setFloat(key:String, val:Float):Void {
untyped __string_hash_set_float(__cpp__("HX_MAP_THIS"), key, val);
}
private function getString(key:String):String {
return untyped __string_hash_get_string(h, key);
}
private function getInt(key:String):Int {
return untyped __string_hash_get_int(h, key);
}
private function getBool(key:String):Bool {
return untyped __string_hash_get_bool(h, key);
}
private function getFloat(key:String):Float {
return untyped __string_hash_get_float(h, key);
}
#end
}

View File

@ -0,0 +1,101 @@
/*
* 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;
@:headerClassCode("
inline void set(Dynamic key, ::null value) { __object_hash_set(HX_MAP_THIS,key,value,true); }
inline void set(Dynamic key, bool value) { __object_hash_set(HX_MAP_THIS,key,value,true); }
inline void set(Dynamic key, char value) { __object_hash_set_int(HX_MAP_THIS,key,value,true); }
inline void set(Dynamic key, unsigned char value) { __object_hash_set_int(HX_MAP_THIS,key,value,true); }
inline void set(Dynamic key, signed char value) { __object_hash_set_int(HX_MAP_THIS,key,value,true); }
inline void set(Dynamic key, short value) { __object_hash_set_int(HX_MAP_THIS,key,value,true); }
inline void set(Dynamic key, unsigned short value) { __object_hash_set_int(HX_MAP_THIS,key,value,true); }
inline void set(Dynamic key, int value) { __object_hash_set_int(HX_MAP_THIS,key,value,true); }
inline void set(Dynamic key, unsigned int value) { __object_hash_set_int(HX_MAP_THIS,key,value,true); }
inline void set(Dynamic key, float value) { __object_hash_set_float(HX_MAP_THIS,key,value,true); }
inline void set(Dynamic key, double value) { __object_hash_set_float(HX_MAP_THIS,key,value,true); }
inline void set(Dynamic key, ::String value) { __object_hash_set_string(HX_MAP_THIS,key,value,true); }
template<typename V, typename H>
inline void set(Dynamic key, const ::cpp::Struct<V,H> &value) {__object_hash_set(HX_MAP_THIS,key,value,true); }
template<typename V>
inline void set(Dynamic key, const ::cpp::Pointer<V> &value) {__object_hash_set(HX_MAP_THIS,key,(Dynamic)value,true ); }
template<typename V>
inline void set(Dynamic key, const ::cpp::Function<V> &value) {__object_hash_set(HX_MAP_THIS,key,(Dynamic)value,true ); }
")
@:coreApi
class WeakMap<K:{}, V> implements haxe.Constraints.IMap<K, V> {
@:ifFeature("haxe.ds.WeakMap.*")
private var h:Dynamic;
public function new():Void {}
public function set(key:K, value:V):Void {
untyped __global__.__object_hash_set(__cpp__("HX_MAP_THIS"), key, value, true);
}
public function get(key:K):Null<V> {
return untyped __global__.__object_hash_get(h, key);
}
public function exists(key:K):Bool {
return untyped __global__.__object_hash_exists(h, key);
}
public function remove(key:K):Bool {
return untyped __global__.__object_hash_remove(h, key);
}
public function keys():Iterator<K> {
var a:Array<K> = untyped __global__.__object_hash_keys(h);
return a.iterator();
}
public function iterator():Iterator<V> {
var a:Array<Dynamic> = untyped __global__.__object_hash_values(h);
return a.iterator();
}
public inline function keyValueIterator():KeyValueIterator<K, V> {
return new haxe.iterators.MapKeyValueIterator(this);
}
public function copy():WeakMap<K, V> {
var copied = new WeakMap();
for (key in keys())
copied.set(key, get(key));
return copied;
}
public function toString():String {
return untyped __global__.__object_hash_to_string(h);
}
public function clear():Void {
#if (hxcpp_api_level >= 400)
return untyped __global__.__object_hash_clear(h);
#else
h = null;
#end
}
}

View File

@ -0,0 +1,71 @@
/*
* 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;
@:coreApi @:buildXml('<include name="${HXCPP}/src/hx/libs/zlib/Build.xml" />')
class Compress {
var s:Dynamic;
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} {
return _deflate_buffer(s, src.getData(), srcPos, dst.getData(), dstPos);
}
public function setFlushMode(f:FlushMode):Void {
_set_flush_mode(s, Std.string(f));
}
public function close():Void {
_deflate_end(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";
return out.sub(0, r.write);
}
@:native("_hx_deflate_init")
extern static function _deflate_init(level:Int):Dynamic;
@:native("_hx_deflate_bound")
extern static function _deflate_bound(handle:Dynamic, length:Int):Int;
@:native("_hx_deflate_buffer")
extern static function _deflate_buffer(handle:Dynamic, src:haxe.io.BytesData, srcPos:Int, dest:haxe.io.BytesData,
destPos:Int):{done:Bool, read:Int, write:Int};
@:native("_hx_deflate_end")
extern static function _deflate_end(handle:Dynamic):Void;
@:native("_hx_zip_set_flush_mode")
extern static function _set_flush_mode(handle:Dynamic, flushMode:String):Void;
}

View File

@ -0,0 +1,76 @@
/*
* 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;
@:coreApi @:buildXml('<include name="${HXCPP}/src/hx/libs/zlib/Build.xml"/>')
class Uncompress {
var s:Dynamic;
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} {
return _inflate_buffer(s, src.getData(), srcPos, dst.getData(), dstPos);
}
public function setFlushMode(f:FlushMode):Void {
_set_flush_mode(s, untyped f.__Tag());
}
public function close():Void {
_inflate_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();
}
@:native("_hx_inflate_init")
extern static function _inflate_init(windowBits:Dynamic):Dynamic;
@:native("_hx_inflate_buffer")
extern static function _inflate_buffer(handle:Dynamic, src:haxe.io.BytesData, srcPos:Int, dest:haxe.io.BytesData,
destPos:Int):{done:Bool, read:Int, write:Int};
@:native("_hx_inflate_end")
extern static function _inflate_end(handle:Dynamic):Void;
@:native("_hx_zip_set_flush_mode")
extern static function _set_flush_mode(handle:Dynamic, flushMode:String):Void;
}

View File

@ -0,0 +1,113 @@
/*
* 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;
import cpp.NativeSys;
@:buildXml('<include name="${HXCPP}/src/hx/libs/std/Build.xml"/>')
@:coreApi
class FileSystem {
public static function exists(path:String):Bool {
return NativeSys.sys_exists(makeCompatiblePath(path));
}
public static function rename(path:String, newPath:String):Void {
NativeSys.sys_rename(path, newPath);
}
public static function stat(path:String):FileStat {
var s:FileStat = NativeSys.sys_stat(makeCompatiblePath(path));
if (s == null)
return {
gid: 0,
uid: 0,
atime: Date.fromTime(0),
mtime: Date.fromTime(0),
ctime: Date.fromTime(0),
dev: 0,
ino: 0,
nlink: 0,
rdev: 0,
size: 0,
mode: 0
};
s.atime = Date.fromTime(1000.0 * (untyped s.atime));
s.mtime = Date.fromTime(1000.0 * (untyped s.mtime));
s.ctime = Date.fromTime(1000.0 * (untyped s.ctime));
return s;
}
public static function fullPath(relPath:String):String {
return NativeSys.file_full_path(relPath);
}
public static function absolutePath(relPath:String):String {
if (haxe.io.Path.isAbsolute(relPath))
return relPath;
return haxe.io.Path.join([Sys.getCwd(), relPath]);
}
inline static function kind(path:String):String {
return NativeSys.sys_file_type(makeCompatiblePath(path));
}
public static function isDirectory(path:String):Bool {
return kind(path) == "dir";
}
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) && !NativeSys.sys_create_dir(part, 493))
throw "Could not create directory:" + part;
}
}
public static function deleteFile(path:String):Void {
NativeSys.file_delete(path);
}
public static function deleteDirectory(path:String):Void {
NativeSys.sys_remove_dir(path);
}
public static function readDirectory(path:String):Array<String> {
return NativeSys.sys_read_dir(path);
}
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);
}
}
}

View File

@ -0,0 +1,228 @@
/*
* 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;
@:keep
private class D {
@:native("_hx_mysql_connect")
extern public static function connect(params:Dynamic):Dynamic;
@:native("_hx_mysql_select_db")
extern public static function select_db(handle:Dynamic, db:String):Void;
@:native("_hx_mysql_request")
extern public static function request(handle:Dynamic, req:String):Dynamic;
@:native("_hx_mysql_close")
extern public static function close(handle:Dynamic):Dynamic;
@:native("_hx_mysql_escape")
extern public static function escape(handle:Dynamic, str:String):String;
@:native("_hx_mysql_result_get_length")
extern public static function result_get_length(handle:Dynamic):Int;
@:native("_hx_mysql_result_get_nfields")
extern public static function result_get_nfields(handle:Dynamic):Int;
@:native("_hx_mysql_result_next")
extern public static function result_next(handle:Dynamic):Dynamic;
@:native("_hx_mysql_result_get")
extern public static function result_get(handle:Dynamic, i:Int):String;
@:native("_hx_mysql_result_get_int")
extern public static function result_get_int(handle:Dynamic, i:Int):Int;
@:native("_hx_mysql_result_get_float")
extern public static function result_get_float(handle:Dynamic, i:Int):Float;
@:native("_hx_mysql_result_get_fields_names")
extern public static function result_fields_names(handle:Dynamic):Array<String>;
@:native("_hx_mysql_set_conversion")
extern public static function set_conv_funs(charsToBytes:cpp.Callable<Dynamic->Dynamic>, intToDate:cpp.Callable<Float->Dynamic>):Void;
public static function charsToBytes(data:Dynamic):Dynamic
return haxe.io.Bytes.ofData(data);
public static function secondsToDate(seconds:Float):Dynamic
return Date.fromTime(seconds * 1000);
}
private class MysqlResultSet implements sys.db.ResultSet {
public var length(get, null):Int;
public var nfields(get, null):Int;
private var __r:Dynamic;
private var cache:Dynamic;
public function new(r:Dynamic) {
__r = r;
}
private function get_length() {
return D.result_get_length(__r);
}
private function get_nfields() {
return D.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 = D.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) {
return D.result_get(__r, n);
}
public function getIntResult(n:Int):Int {
return D.result_get_int(__r, n);
}
public function getFloatResult(n:Int):Float {
return D.result_get_float(__r, n);
}
public function getFieldsNames():Array<String> {
var a = D.result_fields_names(__r);
return a;
}
}
private class MysqlConnection implements sys.db.Connection {
private var __c:Dynamic;
public function new(c:Dynamic) {
__c = c;
D.set_conv_funs(cpp.Function.fromStaticFunction(D.charsToBytes), cpp.Function.fromStaticFunction(D.secondsToDate));
}
public function request(s:String):sys.db.ResultSet {
var r = D.request(this.__c, s);
return new MysqlResultSet(r);
}
public function close() {
D.close(__c);
}
public function escape(s:String) {
return D.escape(__c, s);
}
public function quote(s:String) {
return "'" + escape(s) + "'";
}
public function addValue(s:StringBuf, v:Dynamic) {
if (v == null) {
s.add(v);
} else if (Std.isOfType(v, Bool)) {
s.add(v ? 1 : 0);
} else {
var t:Int = untyped v.__GetType();
if (t == 0xff)
s.add(v);
else if (t == 2)
s.add(untyped v.__GetInt() ? "1".code : "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");
}
private static var __use_date = Date;
}
@:buildXml('<include name="${HXCPP}/src/hx/libs/mysql/Build.xml"/>')
@:coreApi class Mysql {
public static function connect(params:{
host:String,
?port:Int,
user:String,
pass:String,
?socket:String,
?database:String
}):sys.db.Connection {
var o = {
host: params.host,
port: if (params.port == null) 3306 else params.port,
user: params.user,
pass: params.pass,
socket: if (params.socket == null) null else params.socket
};
var c = D.connect(o);
if (params.database != null) {
try {
D.select_db(c, params.database);
} catch (e:Dynamic) {
D.close(c);
cpp.Lib.rethrow(e);
}
}
return new MysqlConnection(c);
}
}

View File

@ -0,0 +1,203 @@
/*
* 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 SqliteConnection implements Connection {
var c:Dynamic;
public function new(file:String) {
c = _connect(file);
}
public function close() {
_close(c);
}
public function request(s:String):ResultSet {
try {
return new SqliteResultSet(_request(c, s));
} catch (e:String) {
throw "Error while executing " + s + " (" + e + ")";
}
}
public function escape(s:String) {
return s.split("'").join("''");
}
public function quote(s:String) {
if (s.indexOf("\000") >= 0) {
var hexChars = new Array<String>();
for (i in 0...s.length)
hexChars.push(StringTools.hex(StringTools.fastCodeAt(s, i), 2));
return "x'" + hexChars.join("") + "'";
}
return "'" + s.split("'").join("''") + "'";
}
public function addValue(s:StringBuf, v:Dynamic) {
if (v == null) {
s.add(v);
} else if (Std.isOfType(v, Bool)) {
s.add(v ? 1 : 0);
} else {
var t:Int = untyped v.__GetType();
if (t == 0xff)
s.add(v);
else if (t == 2)
s.add(untyped v.__GetInt());
else
s.add(quote(Std.string(v)));
}
}
public function lastInsertId():Int {
return _last_id(c);
}
public function dbName() {
return "SQLite";
}
public function startTransaction() {
request("BEGIN TRANSACTION");
}
public function commit() {
request("COMMIT");
}
public function rollback() {
request("ROLLBACK");
}
@:native("_hx_sqlite_connect")
extern public static function _connect(filename:String):Dynamic;
@:native("_hx_sqlite_request")
extern public static function _request(handle:Dynamic, req:String):Dynamic;
@:native("_hx_sqlite_close")
extern public static function _close(handle:Dynamic):Void;
@:native("_hx_sqlite_last_insert_id")
extern public static function _last_id(handle:Dynamic):Int;
}
private class SqliteResultSet implements ResultSet {
public var length(get, null):Int;
public var nfields(get, null):Int;
var r:Dynamic;
var cache:List<Dynamic>;
public function new(r:Dynamic) {
cache = new List();
this.r = r;
hasNext(); // execute the request
}
function get_length() {
if (nfields != 0) {
while (true) {
var c = result_next(r);
if (c == null)
break;
cache.add(c);
}
return cache.length;
}
return result_get_length(r);
}
function get_nfields() {
return result_get_nfields(r);
}
public function hasNext() {
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 result_next(r);
}
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) {
return new String(result_get(r, n));
}
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> {
throw new haxe.exceptions.NotImplementedException();
}
@:native("_hx_sqlite_result_next")
extern public static function result_next(handle:Dynamic):Dynamic;
@:native("_hx_sqlite_result_get_length")
extern public static function result_get_length(handle:Dynamic):Int;
@:native("_hx_sqlite_result_get_nfields")
extern public static function result_get_nfields(handle:Dynamic):Int;
@:native("_hx_sqlite_result_get")
extern public static function result_get(handle:Dynamic, i:Int):String;
@:native("_hx_sqlite_result_get_int")
extern public static function result_get_int(handle:Dynamic, i:Int):Int;
@:native("_hx_sqlite_result_get_float")
extern public static function result_get_float(handle:Dynamic, i:Int):Float;
}
@:buildXml('<include name="${HXCPP}/src/hx/libs/sqlite/Build.xml"/>')
@:coreApi class Sqlite {
public static function open(file:String):Connection {
return new SqliteConnection(file);
}
}

View File

@ -0,0 +1,76 @@
/*
* 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 cpp.NativeFile;
@:coreApi
class File {
public static function getContent(path:String):String {
return NativeFile.file_contents_string(path);
}
public static function getBytes(path:String):haxe.io.Bytes {
var data = NativeFile.file_contents_bytes(path);
return haxe.io.Bytes.ofData(data);
}
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 {
return untyped new FileInput(NativeFile.file_open(path, (if (binary) "rb" else "r")));
}
public static function write(path:String, binary:Bool = true):FileOutput {
return untyped new FileOutput(NativeFile.file_open(path, (if (binary) "wb" else "w")));
}
public static function append(path:String, binary:Bool = true):FileOutput {
return untyped new FileOutput(NativeFile.file_open(path, (if (binary) "ab" else "a")));
}
public static function update(path:String, binary:Bool = true):FileOutput {
if (!FileSystem.exists(path)) {
write(path).close();
}
return untyped new FileOutput(NativeFile.file_open(path, (if (binary) "rb+" else "r+")));
}
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();
}
}

View File

@ -0,0 +1,74 @@
/*
* 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.FileSeek;
import cpp.NativeFile;
@:coreApi
class FileInput extends haxe.io.Input {
private var __f:Dynamic;
function new(f:Dynamic):Void {
__f = f;
}
public override function readByte():Int {
return try {
NativeFile.file_read_char(__f);
} catch (e:Dynamic) {
if (untyped e.__IsArray())
throw new haxe.io.Eof();
else
throw haxe.io.Error.Custom(e);
}
}
public override function readBytes(s:haxe.io.Bytes, p:Int, l:Int):Int {
return try {
NativeFile.file_read(__f, s.getData(), p, l);
} catch (e:Dynamic) {
if (untyped e.__IsArray())
throw new haxe.io.Eof();
else
throw haxe.io.Error.Custom(e);
}
}
public override function close():Void {
super.close();
NativeFile.file_close(__f);
}
public function seek(p:Int, pos:FileSeek):Void {
NativeFile.file_seek(__f, p, pos == SeekBegin ? 0 : pos == SeekCur ? 1 : 2);
}
public function tell():Int {
return NativeFile.file_tell(__f);
}
public function eof():Bool {
return NativeFile.file_eof(__f);
}
}

View File

@ -0,0 +1,63 @@
/*
* 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.FileSeek;
import cpp.NativeFile;
@:coreApi
class FileOutput extends haxe.io.Output {
private var __f:Dynamic;
function new(f:Dynamic):Void {
__f = f;
}
public override function writeByte(c:Int):Void {
try
NativeFile.file_write_char(__f, c)
catch (e:Dynamic)
throw haxe.io.Error.Custom(e);
}
public override function writeBytes(s:haxe.io.Bytes, p:Int, l:Int):Int {
return try NativeFile.file_write(__f, s.getData(), p, l) catch (e:Dynamic) throw haxe.io.Error.Custom(e);
}
public override function flush():Void {
NativeFile.file_flush(__f);
}
public override function close():Void {
super.close();
NativeFile.file_close(__f);
}
public function seek(p:Int, pos:FileSeek):Void {
NativeFile.file_seek(__f, p, pos == SeekBegin ? 0 : pos == SeekCur ? 1 : 2);
}
public function tell():Int {
return NativeFile.file_tell(__f);
}
}

View File

@ -0,0 +1,120 @@
/*
* 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 cpp.NativeProcess;
private class Stdin extends haxe.io.Output {
var p:Dynamic;
var buf:haxe.io.Bytes;
public function new(p:Dynamic) {
this.p = p;
buf = haxe.io.Bytes.alloc(1);
}
public override function close() {
super.close();
NativeProcess.process_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 {
try {
return NativeProcess.process_stdin_write(p, buf.getData(), pos, len);
} catch (e:Dynamic) {
throw new haxe.io.Eof();
}
return 0;
}
}
private class Stdout extends haxe.io.Input {
var p:Dynamic;
var out:Bool;
var buf:haxe.io.Bytes;
public function new(p:Dynamic, 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 result:Int;
try {
result = out ? NativeProcess.process_stdout_read(p, str.getData(), pos, len) : NativeProcess.process_stderr_read(p, str.getData(), pos, len);
} catch (e:Dynamic) {
throw new haxe.io.Eof();
}
if (result == 0)
throw new haxe.io.Eof();
return result;
}
}
@:coreApi
class Process {
var p:Dynamic;
public var stdout(default, null):haxe.io.Input;
public var stderr(default, null):haxe.io.Input;
public var stdin(default, null):haxe.io.Output;
public function new(cmd:String, ?args:Array<String>, ?detached:Bool):Void {
if (detached)
throw "Detached process is not supported on this platform";
p = try NativeProcess.process_run(cmd, args) catch (e:Dynamic) throw "Process creation failure : " + cmd;
stdin = new Stdin(p);
stdout = new Stdout(p, true);
stderr = new Stdout(p, false);
}
public function getPid():Int {
return NativeProcess.process_pid(p);
}
public function exitCode(block:Bool = true):Null<Int> {
if (block == false)
throw "Non blocking exitCode() not supported on this platform";
return NativeProcess.process_exit(p);
}
public function close():Void {
NativeProcess.process_close(p);
}
public function kill():Void {
NativeProcess.process_kill(p);
}
}

View File

@ -0,0 +1,59 @@
/*
* 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 cpp.NativeSocket;
@:coreApi
class Host {
public var host(default, null):String;
public var ip(default, null):Int;
private var ipv6(default, null):haxe.io.BytesData;
public function new(name:String):Void {
host = name;
try {
ip = NativeSocket.host_resolve(name);
} catch (e:Dynamic) {
ipv6 = NativeSocket.host_resolve_ipv6(name);
}
}
public function toString():String {
return ipv6 == null ? NativeSocket.host_to_string(ip) : NativeSocket.host_to_string_ipv6(ipv6);
}
public function reverse():String {
return ipv6 == null ? NativeSocket.host_reverse(ip) : NativeSocket.host_reverse_ipv6(ipv6);
}
public static function localhost():String {
return NativeSocket.host_local();
}
static function __init__():Void {
NativeSocket.socket_init();
}
}

View File

@ -0,0 +1,273 @@
/*
* 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;
import cpp.NativeSocket;
import cpp.NativeString;
import cpp.Pointer;
private class SocketInput extends haxe.io.Input {
var __s:Dynamic;
public function new(s:Dynamic) {
__s = s;
}
public override function readByte() {
return try {
NativeSocket.socket_recv_char(__s);
} catch (e:Dynamic) {
if (e == "Blocking")
throw Blocked;
else if (__s == null)
throw Custom(e);
else
throw new haxe.io.Eof();
}
}
public override function readBytes(buf:haxe.io.Bytes, pos:Int, len:Int):Int {
var r;
if (__s == null)
throw "Invalid handle";
try {
r = NativeSocket.socket_recv(__s, buf.getData(), pos, len);
} catch (e:Dynamic) {
if (e == "Blocking")
throw Blocked;
else
throw Custom(e);
}
if (r == 0)
throw new haxe.io.Eof();
return r;
}
public override function close() {
super.close();
if (__s != null)
NativeSocket.socket_close(__s);
}
}
private class SocketOutput extends haxe.io.Output {
var __s:Dynamic;
public function new(s:Dynamic) {
__s = s;
}
public override function writeByte(c:Int) {
if (__s == null)
throw "Invalid handle";
try {
NativeSocket.socket_send_char(__s, c);
} catch (e:Dynamic) {
if (e == "Blocking")
throw Blocked;
else
throw Custom(e);
}
}
public override function writeBytes(buf:haxe.io.Bytes, pos:Int, len:Int):Int {
return try {
NativeSocket.socket_send(__s, buf.getData(), pos, len);
} catch (e:Dynamic) {
if (e == "Blocking")
throw Blocked;
else if (e == "EOF")
throw new haxe.io.Eof();
else
throw Custom(e);
}
}
public override function close() {
super.close();
if (__s != null)
NativeSocket.socket_close(__s);
}
}
@:coreApi
class Socket {
private var __s:Dynamic;
// We need to keep these values so that we can restore
// them if we re-create the socket for ipv6 as in
// connect() and bind() below.
private var __timeout:Float = 0.0;
private var __blocking:Bool = true;
private var __fastSend:Bool = false;
public var input(default, null):haxe.io.Input;
public var output(default, null):haxe.io.Output;
public var custom:Dynamic;
public function new():Void {
init();
}
private function init():Void {
if (__s == null)
__s = NativeSocket.socket_new(false);
// Restore these values if they changed. This can happen
// in connect() and bind() if using an ipv6 address.
setTimeout(__timeout);
setBlocking(__blocking);
setFastSend(__fastSend);
input = new SocketInput(__s);
output = new SocketOutput(__s);
}
public function close():Void {
NativeSocket.socket_close(__s);
untyped {
var input:SocketInput = cast input;
var output:SocketOutput = cast output;
input.__s = null;
output.__s = null;
}
input.close();
output.close();
}
public function read():String {
var bytes:haxe.io.BytesData = NativeSocket.socket_read(__s);
if (bytes == null)
return "";
var arr:Array<cpp.Char> = cast bytes;
return NativeString.fromPointer(Pointer.ofArray(arr));
}
public function write(content:String):Void {
NativeSocket.socket_write(__s, haxe.io.Bytes.ofString(content).getData());
}
public function connect(host:Host, port:Int):Void {
try {
if (host.ip == 0 && host.host != "0.0.0.0") {
// hack, hack, hack
var ipv6:haxe.io.BytesData = Reflect.field(host, "ipv6");
if (ipv6 != null) {
close();
__s = NativeSocket.socket_new_ip(false, true);
init();
NativeSocket.socket_connect_ipv6(__s, ipv6, port);
} else
throw "Unresolved host";
} else
NativeSocket.socket_connect(__s, host.ip, port);
} catch (s:String) {
if (s == "Invalid socket handle")
throw "Failed to connect on " + host.toString() + ":" + port;
else if (s == "Blocking") {
// Do nothing, this is not a real error, it simply indicates
// that a non-blocking connect is in progress
} else
cpp.Lib.rethrow(s);
}
}
public function listen(connections:Int):Void {
NativeSocket.socket_listen(__s, connections);
}
public function shutdown(read:Bool, write:Bool):Void {
NativeSocket.socket_shutdown(__s, read, write);
}
public function bind(host:Host, port:Int):Void {
if (host.ip == 0 && host.host != "0.0.0.0") {
var ipv6:haxe.io.BytesData = Reflect.field(host, "ipv6");
if (ipv6 != null) {
close();
__s = NativeSocket.socket_new_ip(false, true);
init();
NativeSocket.socket_bind_ipv6(__s, ipv6, port);
} else
throw "Unresolved host";
} else
NativeSocket.socket_bind(__s, host.ip, port);
}
public function accept():Socket {
var c = NativeSocket.socket_accept(__s);
var s = Type.createEmptyInstance(Socket);
s.__s = c;
s.input = new SocketInput(c);
s.output = new SocketOutput(c);
return s;
}
public function peer():{host:Host, port:Int} {
var a:Dynamic = NativeSocket.socket_peer(__s);
if (a == null) {
return null;
}
var h = new Host("127.0.0.1");
untyped h.ip = a[0];
return {host: h, port: a[1]};
}
public function host():{host:Host, port:Int} {
var a:Dynamic = NativeSocket.socket_host(__s);
if (a == null) {
return null;
}
var h = new Host("127.0.0.1");
untyped h.ip = a[0];
return {host: h, port: a[1]};
}
public function setTimeout(timeout:Float):Void {
__timeout = timeout;
NativeSocket.socket_set_timeout(__s, timeout);
}
public function waitForRead():Void {
select([this], null, null, null);
}
public function setBlocking(b:Bool):Void {
__blocking = b;
NativeSocket.socket_set_blocking(__s, b);
}
public function setFastSend(b:Bool):Void {
__fastSend = b;
NativeSocket.socket_set_fast_send(__s, b);
}
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 neko_array = NativeSocket.socket_select(read, write, others, timeout);
if (neko_array == null)
throw "Select error";
return @:fixed {
read:neko_array[0], write:neko_array[1], others:neko_array[2]
};
}
}

View File

@ -0,0 +1,64 @@
/*
* 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;
import cpp.NativeSocket;
@:coreApi
class UdpSocket extends Socket {
private override function init():Void {
__s = NativeSocket.socket_new(true);
super.init();
}
public function sendTo(buf:haxe.io.Bytes, pos:Int, len:Int, addr:Address):Int {
return try {
NativeSocket.socket_send_to(__s, buf.getData(), pos, len, addr);
} catch (e:Dynamic) {
if (e == "Blocking")
throw Blocked;
else
throw Custom(e);
}
}
public function readFrom(buf:haxe.io.Bytes, pos:Int, len:Int, addr:Address):Int {
var r;
try {
r = NativeSocket.socket_recv_from(__s, buf.getData(), pos, len, addr);
} catch (e:Dynamic) {
if (e == "Blocking")
throw Blocked;
else
throw Custom(e);
}
if (r == 0)
throw new haxe.io.Eof();
return r;
}
public function setBroadcast(b:Bool):Void {
NativeSocket.socket_set_broadcast(__s, b);
}
}

View File

@ -0,0 +1,136 @@
/*
* 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 cpp.NativeSsl;
@:coreApi
class Certificate {
var __h:Null<Certificate>;
var __x:Dynamic;
@:allow(sys.ssl.Socket)
function new(x:Dynamic, ?h:Certificate) {
__x = x;
__h = h;
}
public static function loadFile(file:String):Certificate {
return new Certificate(NativeSsl.cert_load_file(file));
}
public static function loadPath(path:String):Certificate {
return new Certificate(NativeSsl.cert_load_path(path));
}
public static function fromString(str:String):Certificate {
return new Certificate(NativeSsl.cert_add_pem(null, str));
}
public static function loadDefaults():Certificate {
var x = NativeSsl.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> {
return NativeSsl.cert_get_altnames(__x);
}
public function subject(field:String):Null<String> {
return NativeSsl.cert_get_subject(__x, field);
}
public function issuer(field:String):Null<String> {
return NativeSsl.cert_get_issuer(__x, field);
}
function get_notBefore():Date {
var a = NativeSsl.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 = NativeSsl.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 = NativeSsl.cert_get_next(__x);
return n == null ? null : new Certificate(n, __h == null ? this : __h);
}
public function add(pem:String):Void {
NativeSsl.cert_add_pem(__x, pem);
}
public function addDER(der:haxe.io.Bytes):Void {
NativeSsl.cert_add_der(__x, der.getData());
}
static function __init__():Void {
NativeSsl.init();
}
}

View File

@ -0,0 +1,40 @@
/*
* 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 cpp.NativeSsl;
@:coreApi
class Digest {
public static function make(data:haxe.io.Bytes, alg:DigestAlgorithm):haxe.io.Bytes {
return haxe.io.Bytes.ofData(NativeSsl.dgst_make(data.getData(), alg));
}
public static function sign(data:haxe.io.Bytes, privKey:Key, alg:DigestAlgorithm):haxe.io.Bytes {
return haxe.io.Bytes.ofData(NativeSsl.dgst_sign(data.getData(), @:privateAccess privKey.__k, alg));
}
public static function verify(data:haxe.io.Bytes, signature:haxe.io.Bytes, pubKey:Key, alg:DigestAlgorithm):Bool {
return NativeSsl.dgst_verify(data.getData(), signature.getData(), @:privateAccess pubKey.__k, alg);
}
}

View File

@ -0,0 +1,57 @@
/*
* 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 cpp.NativeSsl;
private typedef PKEY = Dynamic;
@:coreApi
class Key {
private var __k:PKEY;
private function new(k:PKEY) {
__k = k;
}
public static function loadFile(file:String, ?isPublic:Bool, ?pass:String):Key {
var data = sys.io.File.getBytes(file);
var str = cpp.Lib.stringReference(data);
if (str.indexOf("-----BEGIN ") >= 0)
return readPEM(str, isPublic == true, pass);
else
return readDER(data, isPublic == true);
}
public static function readPEM(data:String, isPublic:Bool, ?pass:String):Key {
return new Key(NativeSsl.key_from_pem(data, isPublic, pass));
}
public static function readDER(data:haxe.io.Bytes, isPublic:Bool):Key {
return new Key(NativeSsl.key_from_der(data.getData(), isPublic));
}
static function __init__():Void {
NativeSsl.init();
}
}

View File

@ -0,0 +1,297 @@
/*
* 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 cpp.NativeSocket;
import cpp.NativeSsl;
private typedef SocketHandle = Dynamic;
private typedef CONF = Dynamic;
private typedef SSL = Dynamic;
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() {
return try {
__s.handshake();
NativeSsl.ssl_recv_char(@:privateAccess __s.ssl);
} catch (e:Dynamic) {
if (e == "Blocking")
throw haxe.io.Error.Blocked;
else if (__s == null)
throw haxe.io.Error.Custom(e);
else
throw new haxe.io.Eof();
}
}
public override function readBytes(buf:haxe.io.Bytes, pos:Int, len:Int):Int {
var r:Int;
if (__s == null)
throw "Invalid handle";
try {
__s.handshake();
r = NativeSsl.ssl_recv(@:privateAccess __s.ssl, buf.getData(), pos, len);
} catch (e:Dynamic) {
if (e == "Blocking")
throw haxe.io.Error.Blocked;
else
throw haxe.io.Error.Custom(e);
}
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) {
if (__s == null)
throw "Invalid handle";
try {
__s.handshake();
NativeSsl.ssl_send_char(@:privateAccess __s.ssl, c);
} catch (e:Dynamic) {
if (e == "Blocking")
throw haxe.io.Error.Blocked;
else
throw haxe.io.Error.Custom(e);
}
}
public override function writeBytes(buf:haxe.io.Bytes, pos:Int, len:Int):Int {
return try {
__s.handshake();
NativeSsl.ssl_send(@:privateAccess __s.ssl, buf.getData(), pos, len);
} catch (e:Dynamic) {
if (e == "Blocking")
throw haxe.io.Error.Blocked;
else
throw haxe.io.Error.Custom(e);
}
}
public override function close() {
super.close();
if (__s != null)
__s.close();
}
}
@:coreApi
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:CONF;
private var ssl:SSL;
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:Dynamic;
private var handshakeDone:Bool;
private override function init():Void {
__s = NativeSocket.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) {}
}
caCert = DEFAULT_CA;
verifyCert = DEFAULT_VERIFY_CERT;
}
public override function connect(host:sys.net.Host, port:Int):Void {
try {
conf = buildSSLConfig(false);
ssl = NativeSsl.ssl_new(conf);
handshakeDone = false;
NativeSsl.ssl_set_socket(ssl, __s);
if (hostname == null)
hostname = host.host;
if (hostname != null)
NativeSsl.ssl_set_hostname(ssl, hostname);
NativeSocket.socket_connect(__s, host.ip, port);
handshake();
} catch (s:String) {
if (s == "Invalid socket handle")
throw "Failed to connect on " + host.host + ":" + port;
else
cpp.Lib.rethrow(s);
} catch (e:Dynamic) {
cpp.Lib.rethrow(e);
}
}
public function handshake():Void {
if (!handshakeDone) {
try {
NativeSsl.ssl_handshake(ssl);
handshakeDone = true;
} catch (e:Dynamic) {
if (e == "Blocking")
throw haxe.io.Error.Blocked;
else
cpp.Lib.rethrow(e);
}
}
}
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 read():String {
handshake();
var b = NativeSsl.ssl_read(ssl);
if (b == null)
return "";
return haxe.io.Bytes.ofData(b).toString();
}
public override function write(content:String):Void {
handshake();
NativeSsl.ssl_write(ssl, haxe.io.Bytes.ofString(content).getData());
}
public override function close():Void {
if (ssl != null)
NativeSsl.ssl_close(ssl);
if (conf != null)
NativeSsl.conf_close(conf);
if (altSNIContexts != null)
sniCallback = null;
NativeSocket.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 = buildSSLConfig(true);
NativeSocket.socket_bind(__s, host.ip, port);
}
public override function accept():Socket {
var c = NativeSocket.socket_accept(__s);
var ssl = NativeSsl.ssl_new(conf);
NativeSsl.ssl_set_socket(ssl, c);
var s = Type.createEmptyInstance(sys.ssl.Socket);
s.__s = c;
s.ssl = ssl;
s.input = new SocketInput(s);
s.output = new SocketOutput(s);
s.handshakeDone = false;
return s;
}
public function peerCertificate():sys.ssl.Certificate {
var x = NativeSsl.ssl_get_peer_certificate(ssl);
return x == null ? null : new sys.ssl.Certificate(x);
}
private function buildSSLConfig(server:Bool):CONF {
var conf:CONF = NativeSsl.conf_new(server);
if (ownCert != null && ownKey != null)
NativeSsl.conf_set_cert(conf, @:privateAccess ownCert.__x, @:privateAccess ownKey.__k);
if (altSNIContexts != null) {
sniCallback = function(servername) {
var servername = new String(cast servername);
for (c in altSNIContexts) {
if (c.match(servername))
return @:privateAccess {
key:c.key.__k, cert:c.cert.__x
};
}
if (ownKey != null && ownCert != null)
return @:privateAccess {
key:ownKey.__k, cert:ownCert.__x
};
return null;
}
NativeSsl.conf_set_servername_callback(conf, sniCallback);
}
if (caCert != null)
NativeSsl.conf_set_ca(conf, caCert == null ? null : @:privateAccess caCert.__x);
if (verifyCert == null)
NativeSsl.conf_set_verify(conf, 2);
else
NativeSsl.conf_set_verify(conf, verifyCert ? 1 : 0);
return conf;
}
static function __init__():Void {
NativeSsl.init();
}
}

View File

@ -0,0 +1,44 @@
/*
* 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;
@:coreApi
class Deque<T> {
var q:Dynamic;
public function new() {
q = untyped __global__.__hxcpp_deque_create();
}
public function add(i:T):Void {
untyped __global__.__hxcpp_deque_add(q, i);
}
public function push(i:T):Void {
untyped __global__.__hxcpp_deque_push(q, i);
}
public function pop(block:Bool):Null<T> {
return untyped __global__.__hxcpp_deque_pop(q, block);
}
}

View File

@ -0,0 +1,40 @@
/*
* 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;
@:coreApi
class Lock {
var l:Dynamic;
public function new() {
l = untyped __global__.__hxcpp_lock_create();
}
public function wait(?timeout:Float = -1):Bool {
return untyped __global__.__hxcpp_lock_wait(l, timeout);
}
public function release():Void {
untyped __global__.__hxcpp_lock_release(l);
}
}

View File

@ -0,0 +1,44 @@
/*
* 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;
@:coreApi
class Mutex {
var m:Dynamic;
public function new() {
m = untyped __global__.__hxcpp_mutex_create();
}
public function acquire():Void {
untyped __global__.__hxcpp_mutex_acquire(m);
}
public function tryAcquire():Bool {
return untyped __global__.__hxcpp_mutex_try(m);
}
public function release():Void {
untyped __global__.__hxcpp_mutex_release(m);
}
}

View File

@ -0,0 +1,189 @@
/*
* 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):Void {
this.sendMessage(msg);
}
public static inline function current():Thread {
return HaxeThread.current();
}
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 readMessage(block:Bool):Dynamic {
return HaxeThread.readMessage(block);
}
function get_events():EventLoop {
if(this.events == null)
throw new NoEventLoopException();
return this.events;
}
@:keep
static public function processEvents() {
HaxeThread.current().events.loop();
}
}
@:callable
@:coreType
private abstract NativeThreadHandle {}
private typedef ThreadHandle = NativeThreadHandle;
private class HaxeThread {
static var threads:Array<{thread:HaxeThread, handle:ThreadHandle}>;
static var threadsMutex:Mutex;
static var mainThreadHandle:ThreadHandle;
static var mainThread:HaxeThread;
static function __init__() {
threads = [];
threadsMutex = new Mutex();
mainThreadHandle = currentHandle();
mainThread = new HaxeThread(currentHandle());
mainThread.events = new EventLoop();
}
public var events(default,null):Null<EventLoop>;
public var handle:ThreadHandle;
final messages = new Deque<Dynamic>();
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(handle);
threads.push({thread:thread, handle:handle});
}
threadsMutex.release();
return thread;
}
public static function create(job:()->Void, withEventLoop:Bool):Thread {
var item = {handle:null, thread:new HaxeThread(null)};
threadsMutex.acquire();
var index = threads.push(item);
threadsMutex.release();
if(withEventLoop)
item.thread.events = new EventLoop();
item.handle = createHandle(() -> {
if(item.thread.handle == null) {
item.handle = currentHandle();
item.thread.handle = item.handle;
}
try {
job();
if(withEventLoop)
item.thread.events.loop();
} catch(e) {
dropThread(item, index);
throw e;
}
dropThread(item, index);
});
item.thread.handle = item.handle;
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(item, probableIndex:Int) {
threadsMutex.acquire();
if(threads[probableIndex] == item) {
threads.splice(probableIndex, 1);
} else {
for(i => item2 in threads) {
if(item2 == item) {
threads.splice(i, 1);
break;
}
}
}
threadsMutex.release();
}
function new(h:ThreadHandle):Void {
handle = h;
}
public inline function sendMessage(msg:Dynamic):Void {
messages.add(msg);
}
static #if !scriptable inline #end function currentHandle():ThreadHandle {
return untyped __global__.__hxcpp_thread_current();
}
static #if !scriptable inline #end function createHandle(callb:Void->Void):ThreadHandle {
return untyped __global__.__hxcpp_thread_create(callb);
}
public static #if !scriptable inline #end function readMessage(block:Bool):Dynamic {
return current().messages.pop(block);
}
}

View File

@ -0,0 +1,45 @@
/*
* 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;
@:coreApi
class Tls<T> {
static var sFreeSlot = 0;
var mTLSID:Int;
public var value(get, set):T;
public function new() {
mTLSID = sFreeSlot++;
}
function get_value():T {
return untyped __global__.__hxcpp_tls_get(mTLSID);
}
function set_value(v:T):T {
untyped __global__.__hxcpp_tls_set(mTLSID, v);
return v;
}
}