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,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.
*/
/**
`Any` is a type that is compatible with any other in both ways.
This means that a value of any type can be assigned to `Any`, and
vice-versa, a value of `Any` type can be assigned to any other type.
It's a more type-safe alternative to `Dynamic`, because it doesn't
support field access or operators and it's bound to monomorphs. So,
to work with the actual value, it needs to be explicitly promoted
to another type.
**/
@:forward.variance
abstract Any(Dynamic) {
@:noCompletion @:to extern inline function __promote<T>():T
return this;
@:noCompletion @:from extern inline static function __cast<T>(value:T):Any
return cast value;
@:noCompletion extern inline function toString():String
return Std.string(this);
}

View File

@ -0,0 +1,333 @@
/*
* 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.
*/
/**
An Array is a storage for values. You can access it using indexes or
with its API.
@see https://haxe.org/manual/std-Array.html
@see https://haxe.org/manual/lf-array-comprehension.html
**/
import haxe.iterators.ArrayKeyValueIterator;
extern class Array<T> {
/**
The length of `this` Array.
**/
var length(default, null):Int;
/**
Creates a new Array.
**/
function new():Void;
/**
Returns a new Array by appending the elements of `a` to the elements of
`this` Array.
This operation does not modify `this` Array.
If `a` is the empty Array `[]`, a copy of `this` Array is returned.
The length of the returned Array is equal to the sum of `this.length`
and `a.length`.
If `a` is `null`, the result is unspecified.
**/
function concat(a:Array<T>):Array<T>;
/**
Returns a string representation of `this` Array, with `sep` separating
each element.
The result of this operation is equal to `Std.string(this[0]) + sep +
Std.string(this[1]) + sep + ... + sep + Std.string(this[this.length-1])`
If `this` is the empty Array `[]`, the result is the empty String `""`.
If `this` has exactly one element, the result is equal to a call to
`Std.string(this[0])`.
If `sep` is null, the result is unspecified.
**/
function join(sep:String):String;
/**
Removes the last element of `this` Array and returns it.
This operation modifies `this` Array in place.
If `this` has at least one element, `this.length` will decrease by 1.
If `this` is the empty Array `[]`, null is returned and the length
remains 0.
**/
function pop():Null<T>;
/**
Adds the element `x` at the end of `this` Array and returns the new
length of `this` Array.
This operation modifies `this` Array in place.
`this.length` increases by 1.
**/
function push(x:T):Int;
/**
Reverse the order of elements of `this` Array.
This operation modifies `this` Array in place.
If `this.length < 2`, `this` remains unchanged.
**/
function reverse():Void;
/**
Removes the first element of `this` Array and returns it.
This operation modifies `this` Array in place.
If `this` has at least one element, `this`.length and the index of each
remaining element is decreased by 1.
If `this` is the empty Array `[]`, `null` is returned and the length
remains 0.
**/
function shift():Null<T>;
/**
Creates a shallow copy of the range of `this` Array, starting at and
including `pos`, up to but not including `end`.
This operation does not modify `this` Array.
The elements are not copied and retain their identity.
If `end` is omitted or exceeds `this.length`, it defaults to the end of
`this` Array.
If `pos` or `end` are negative, their offsets are calculated from the
end of `this` Array by `this.length + pos` and `this.length + end`
respectively. If this yields a negative value, 0 is used instead.
If `pos` exceeds `this.length` or if `end` is less than or equals
`pos`, the result is `[]`.
**/
function slice(pos:Int, ?end:Int):Array<T>;
/**
Sorts `this` Array according to the comparison function `f`, where
`f(x,y)` returns 0 if x == y, a positive Int if x > y and a
negative Int if x < y.
This operation modifies `this` Array in place.
The sort operation is not guaranteed to be stable, which means that the
order of equal elements may not be retained. For a stable Array sorting
algorithm, `haxe.ds.ArraySort.sort()` can be used instead.
If `f` is null, the result is unspecified.
**/
function sort(f:T->T->Int):Void;
/**
Removes `len` elements from `this` Array, starting at and including
`pos`, an returns them.
This operation modifies `this` Array in place.
If `len` is < 0 or `pos` exceeds `this`.length, an empty Array [] is
returned and `this` Array is unchanged.
If `pos` is negative, its value is calculated from the end of `this`
Array by `this.length + pos`. If this yields a negative value, 0 is
used instead.
If the sum of the resulting values for `len` and `pos` exceed
`this.length`, this operation will affect the elements from `pos` to the
end of `this` Array.
The length of the returned Array is equal to the new length of `this`
Array subtracted from the original length of `this` Array. In other
words, each element of the original `this` Array either remains in
`this` Array or becomes an element of the returned Array.
**/
function splice(pos:Int, len:Int):Array<T>;
/**
Returns a string representation of `this` Array.
The result will include the individual elements' String representations
separated by comma. The enclosing [ ] may be missing on some platforms,
use `Std.string()` to get a String representation that is consistent
across platforms.
**/
function toString():String;
/**
Adds the element `x` at the start of `this` Array.
This operation modifies `this` Array in place.
`this.length` and the index of each Array element increases by 1.
**/
function unshift(x:T):Void;
/**
Inserts the element `x` at the position `pos`.
This operation modifies `this` Array in place.
The offset is calculated like so:
- If `pos` exceeds `this.length`, the offset is `this.length`.
- If `pos` is negative, the offset is calculated from the end of `this`
Array, i.e. `this.length + pos`. If this yields a negative value, the
offset is 0.
- Otherwise, the offset is `pos`.
If the resulting offset does not exceed `this.length`, all elements from
and including that offset to the end of `this` Array are moved one index
ahead.
**/
function insert(pos:Int, x:T):Void;
/**
Removes the first occurrence of `x` in `this` Array.
This operation modifies `this` Array in place.
If `x` is found by checking standard equality, it is removed from `this`
Array and all following elements are reindexed accordingly. The function
then returns true.
If `x` is not found, `this` Array is not changed and the function
returns false.
**/
function remove(x:T):Bool;
/**
Returns whether `this` Array contains `x`.
If `x` is found by checking standard equality, the function returns `true`, otherwise
the function returns `false`.
**/
@:pure function contains( x : T ) : Bool;
/**
Returns position of the first occurrence of `x` in `this` Array, searching front to back.
If `x` is found by checking standard equality, the function returns its index.
If `x` is not found, the function returns -1.
If `fromIndex` is specified, it will be used as the starting index to search from,
otherwise search starts with zero index. If it is negative, it will be taken as the
offset from the end of `this` Array to compute the starting index. If given or computed
starting index is less than 0, the whole array will be searched, if it is greater than
or equal to the length of `this` Array, the function returns -1.
**/
function indexOf(x:T, ?fromIndex:Int):Int;
/**
Returns position of the last occurrence of `x` in `this` Array, searching back to front.
If `x` is found by checking standard equality, the function returns its index.
If `x` is not found, the function returns -1.
If `fromIndex` is specified, it will be used as the starting index to search from,
otherwise search starts with the last element index. If it is negative, it will be
taken as the offset from the end of `this` Array to compute the starting index. If
given or computed starting index is greater than or equal to the length of `this` Array,
the whole array will be searched, if it is less than 0, the function returns -1.
**/
function lastIndexOf(x:T, ?fromIndex:Int):Int;
/**
Returns a shallow copy of `this` Array.
The elements are not copied and retain their identity, so
`a[i] == a.copy()[i]` is true for any valid `i`. However,
`a == a.copy()` is always false.
**/
function copy():Array<T>;
/**
Returns an iterator of the Array values.
**/
@:runtime inline function iterator():haxe.iterators.ArrayIterator<T> {
return new haxe.iterators.ArrayIterator(this);
}
/**
Returns an iterator of the Array indices and values.
**/
@:pure @:runtime public inline function keyValueIterator() : ArrayKeyValueIterator<T> {
return new ArrayKeyValueIterator(this);
}
/**
Creates a new Array by applying function `f` to all elements of `this`.
The order of elements is preserved.
If `f` is null, the result is unspecified.
**/
@:runtime inline function map<S>(f:T->S):Array<S> {
#if (cpp && !cppia)
var result = cpp.NativeArray.create(length);
for (i in 0...length) cpp.NativeArray.unsafeSet(result, i, f(cpp.NativeArray.unsafeGet(this, i)));
return result;
#else
return [for (v in this) f(v)];
#end
}
/**
Returns an Array containing those elements of `this` for which `f`
returned true.
The individual elements are not duplicated and retain their identity.
If `f` is null, the result is unspecified.
**/
@:runtime inline function filter(f:T->Bool):Array<T> {
return [for (v in this) if (f(v)) v];
}
/**
Set the length of the Array.
If `len` is shorter than the array's current size, the last
`length - len` elements will be removed. If `len` is longer, the Array
will be extended, with new elements set to a target-specific default
value:
- always null on dynamic targets
- 0, 0.0 or false for Int, Float and Bool respectively on static targets
- null for other types on static targets
**/
function resize(len:Int):Void;
}

View File

@ -0,0 +1,30 @@
/*
* 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.
*/
/**
An abstract type that represents a Class.
See `Type` for the Haxe Reflection API.
@see https://haxe.org/manual/types-class-instance.html
**/
@:coreType @:runtimeValue abstract Class<T> {}

View File

@ -0,0 +1,183 @@
/*
* 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.
*/
/**
The Date class provides a basic structure for date and time related
information. Date instances can be created by
- `new Date()` for a specific date,
- `Date.now()` to obtain information about the current time,
- `Date.fromTime()` with a given timestamp or
- `Date.fromString()` by parsing from a String.
There are some extra functions available in the `DateTools` class.
In the context of Haxe dates, a timestamp is defined as the number of
milliseconds elapsed since 1st January 1970 UTC.
## Supported range
Due to platform limitations, only dates in the range 1970 through 2038 are
supported consistently. Some targets may support dates outside this range,
depending on the OS at runtime. The `Date.fromTime` method will not work with
timestamps outside the range on any target.
**/
extern class Date {
/**
Creates a new date object from the given arguments.
The behaviour of a Date instance is only consistent across platforms if
the the arguments describe a valid date.
- month: 0 to 11 (note that this is zero-based)
- day: 1 to 31
- hour: 0 to 23
- min: 0 to 59
- sec: 0 to 59
**/
function new(year:Int, month:Int, day:Int, hour:Int, min:Int, sec:Int):Void;
/**
Returns the timestamp (in milliseconds) of `this` date.
On cpp and neko, this function only has a second resolution, so the
result will always be a multiple of `1000.0`, e.g. `1454698271000.0`.
To obtain the current timestamp with better precision on cpp and neko,
see the `Sys.time` API.
For measuring time differences with millisecond accuracy on
all platforms, see `haxe.Timer.stamp`.
**/
function getTime():Float;
/**
Returns the hours of `this` Date (0-23 range) in the local timezone.
**/
function getHours():Int;
/**
Returns the minutes of `this` Date (0-59 range) in the local timezone.
**/
function getMinutes():Int;
/**
Returns the seconds of `this` Date (0-59 range) in the local timezone.
**/
function getSeconds():Int;
/**
Returns the full year of `this` Date (4 digits) in the local timezone.
**/
function getFullYear():Int;
/**
Returns the month of `this` Date (0-11 range) in the local timezone.
Note that the month number is zero-based.
**/
function getMonth():Int;
/**
Returns the day of `this` Date (1-31 range) in the local timezone.
**/
function getDate():Int;
/**
Returns the day of the week of `this` Date (0-6 range, where `0` is Sunday)
in the local timezone.
**/
function getDay():Int;
/**
Returns the hours of `this` Date (0-23 range) in UTC.
**/
function getUTCHours():Int;
/**
Returns the minutes of `this` Date (0-59 range) in UTC.
**/
function getUTCMinutes():Int;
/**
Returns the seconds of `this` Date (0-59 range) in UTC.
**/
function getUTCSeconds():Int;
/**
Returns the full year of `this` Date (4 digits) in UTC.
**/
function getUTCFullYear():Int;
/**
Returns the month of `this` Date (0-11 range) in UTC.
Note that the month number is zero-based.
**/
function getUTCMonth():Int;
/**
Returns the day of `this` Date (1-31 range) in UTC.
**/
function getUTCDate():Int;
/**
Returns the day of the week of `this` Date (0-6 range, where `0` is Sunday)
in UTC.
**/
function getUTCDay():Int;
/**
Returns the time zone difference of `this` Date in the current locale
to UTC, in minutes.
Assuming the function is executed on a machine in a UTC+2 timezone,
`Date.now().getTimezoneOffset()` will return `-120`.
**/
function getTimezoneOffset():Int;
/**
Returns a string representation of `this` Date in the local timezone
using the standard format `YYYY-MM-DD HH:MM:SS`. See `DateTools.format` for
other formatting rules.
**/
function toString():String;
/**
Returns a Date representing the current local time.
**/
static function now():Date;
/**
Creates a Date from the timestamp (in milliseconds) `t`.
**/
static function fromTime(t:Float):Date;
/**
Creates a Date from the formatted string `s`. The following formats are
accepted by the function:
- `"YYYY-MM-DD hh:mm:ss"`
- `"YYYY-MM-DD"`
- `"hh:mm:ss"`
The first two formats expressed a date in local time. The third is a time
relative to the UTC epoch.
**/
static function fromString(s:String):Date;
}

View File

@ -0,0 +1,256 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/**
The DateTools class contains some extra functionalities for handling `Date`
instances and timestamps.
In the context of Haxe dates, a timestamp is defined as the number of
milliseconds elapsed since 1st January 1970.
**/
class DateTools {
#if php
#elseif (neko && !(macro || interp))
static var date_format = neko.Lib.load("std", "date_format", 2);
#else
static var DAY_SHORT_NAMES = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
static var DAY_NAMES = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
static var MONTH_SHORT_NAMES = [
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
];
static var MONTH_NAMES = [
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
];
private static function __format_get(d:Date, e:String):String {
return switch (e) {
case "%":
"%";
case "a":
DAY_SHORT_NAMES[d.getDay()];
case "A":
DAY_NAMES[d.getDay()];
case "b", "h":
MONTH_SHORT_NAMES[d.getMonth()];
case "B":
MONTH_NAMES[d.getMonth()];
case "C":
StringTools.lpad(Std.string(Std.int(d.getFullYear() / 100)), "0", 2);
case "d":
StringTools.lpad(Std.string(d.getDate()), "0", 2);
case "D":
__format(d, "%m/%d/%y");
case "e":
Std.string(d.getDate());
case "F":
__format(d, "%Y-%m-%d");
case "H", "k":
StringTools.lpad(Std.string(d.getHours()), if (e == "H") "0" else " ", 2);
case "I", "l":
var hour = d.getHours() % 12;
StringTools.lpad(Std.string(hour == 0 ? 12 : hour), if (e == "I") "0" else " ", 2);
case "m":
StringTools.lpad(Std.string(d.getMonth() + 1), "0", 2);
case "M":
StringTools.lpad(Std.string(d.getMinutes()), "0", 2);
case "n":
"\n";
case "p":
if (d.getHours() > 11) "PM"; else "AM";
case "r":
__format(d, "%I:%M:%S %p");
case "R":
__format(d, "%H:%M");
case "s":
Std.string(Std.int(d.getTime() / 1000));
case "S":
StringTools.lpad(Std.string(d.getSeconds()), "0", 2);
case "t":
"\t";
case "T":
__format(d, "%H:%M:%S");
case "u":
var t = d.getDay();
if (t == 0) "7" else Std.string(t);
case "w":
Std.string(d.getDay());
case "y":
StringTools.lpad(Std.string(d.getFullYear() % 100), "0", 2);
case "Y":
Std.string(d.getFullYear());
default:
throw new haxe.exceptions.NotImplementedException("Date.format %" + e + "- not implemented yet.");
}
}
private static function __format(d:Date, f:String):String {
var r = new StringBuf();
var p = 0;
while (true) {
var np = f.indexOf("%", p);
if (np < 0)
break;
r.addSub(f, p, np - p);
r.add(__format_get(d, f.substr(np + 1, 1)));
p = np + 2;
}
r.addSub(f, p, f.length - p);
return r.toString();
}
#end
/**
Format the date `d` according to the format `f`. The format is
compatible with the `strftime` standard format, except that there is no
support in Flash and JS for day and months names (due to lack of proper
internationalization API). On Haxe/Neko/Windows, some formats are not
supported.
```haxe
var t = DateTools.format(Date.now(), "%Y-%m-%d_%H:%M:%S");
// 2016-07-08_14:44:05
var t = DateTools.format(Date.now(), "%r");
// 02:44:05 PM
var t = DateTools.format(Date.now(), "%T");
// 14:44:05
var t = DateTools.format(Date.now(), "%F");
// 2016-07-08
```
**/
public static function format(d:Date, f:String):String {
#if (neko && !(macro || interp))
return new String(untyped date_format(d.__t, f.__s));
#elseif php
return php.Global.strftime(f, php.Syntax.int(@:privateAccess d.__t));
#else
return __format(d, f);
#end
}
/**
Returns the result of adding timestamp `t` to Date `d`.
This is a convenience function for calling
`Date.fromTime(d.getTime() + t)`.
**/
public static inline function delta(d:Date, t:Float):Date {
return Date.fromTime(d.getTime() + t);
}
static var DAYS_OF_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
/**
Returns the number of days in the month of Date `d`.
This method handles leap years.
**/
public static function getMonthDays(d:Date):Int {
var month = d.getMonth();
var year = d.getFullYear();
if (month != 1)
return DAYS_OF_MONTH[month];
var isB = ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
return if (isB) 29 else 28;
}
/**
Converts a number of seconds to a timestamp.
**/
public static inline function seconds(n:Float):Float {
return n * 1000.0;
}
/**
Converts a number of minutes to a timestamp.
**/
public static inline function minutes(n:Float):Float {
return n * 60.0 * 1000.0;
}
/**
Converts a number of hours to a timestamp.
**/
public static inline function hours(n:Float):Float {
return n * 60.0 * 60.0 * 1000.0;
}
/**
Converts a number of days to a timestamp.
**/
public static inline function days(n:Float):Float {
return n * 24.0 * 60.0 * 60.0 * 1000.0;
}
/**
Separate a date-time into several components
**/
public static function parse(t:Float) {
var s = t / 1000;
var m = s / 60;
var h = m / 60;
return {
ms: t % 1000,
seconds: Std.int(s % 60),
minutes: Std.int(m % 60),
hours: Std.int(h % 24),
days: Std.int(h / 24),
};
}
/**
Build a date-time from several components
**/
public static function make(o:{
ms:Float,
seconds:Int,
minutes:Int,
hours:Int,
days:Int
}) {
return o.ms + 1000.0 * (o.seconds + 60.0 * (o.minutes + 60.0 * (o.hours + 24.0 * o.days)));
}
#if (js || flash || php || cpp || python)
/**
Retrieve Unix timestamp value from Date components. Takes same argument sequence as the Date constructor.
**/
public static #if (js || flash || php) inline #end function makeUtc(year:Int, month:Int, day:Int, hour:Int, min:Int, sec:Int):Float {
#if (js || flash || python)
return untyped Date.UTC(year, month, day, hour, min, sec);
#elseif php
return php.Global.gmmktime(hour, min, sec, month + 1, day, year) * 1000;
#elseif cpp
return untyped __global__.__hxcpp_utc_date(year, month, day, hour, min, sec) * 1000.0;
#else
// TODO
return 0.;
#end
}
#end
}

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.
*/
/**
The EReg class represents regular expressions.
While basic usage and patterns consistently work across platforms, some more
complex operations may yield different results. This is a necessary trade-
off to retain a certain level of performance.
EReg instances can be created by calling the constructor, or with the
special syntax `~/pattern/modifier`
EReg instances maintain an internal state, which is affected by several of
its methods.
A detailed explanation of the supported operations is available at
<https://haxe.org/manual/std-regex.html>
**/
class EReg {
/**
Creates a new regular expression with pattern `r` and modifiers `opt`.
This is equivalent to the shorthand syntax `~/r/opt`
If `r` or `opt` are null, the result is unspecified.
**/
public function new(r:String, opt:String) {
throw new haxe.exceptions.NotImplementedException("Regular expressions are not implemented for this platform");
}
/**
Tells if `this` regular expression matches String `s`.
This method modifies the internal state.
If `s` is `null`, the result is unspecified.
**/
public function match(s:String):Bool {
return false;
}
/**
Returns the matched sub-group `n` of `this` EReg.
This method should only be called after `this.match` or
`this.matchSub`, and then operates on the String of that operation.
The index `n` corresponds to the n-th set of parentheses in the pattern
of `this` EReg. If no such sub-group exists, the result is unspecified.
If `n` equals 0, the whole matched substring is returned.
**/
public function matched(n:Int):String {
return null;
}
/**
Returns the part to the left of the last matched substring.
If the most recent call to `this.match` or `this.matchSub` did not
match anything, the result is unspecified.
If the global g modifier was in place for the matching, only the
substring to the left of the leftmost match is returned.
The result does not include the matched part.
**/
public function matchedLeft():String {
return null;
}
/**
Returns the part to the right of the last matched substring.
If the most recent call to `this.match` or `this.matchSub` did not
match anything, the result is unspecified.
If the global g modifier was in place for the matching, only the
substring to the right of the leftmost match is returned.
The result does not include the matched part.
**/
public function matchedRight():String {
return null;
}
/**
Returns the position and length of the last matched substring, within
the String which was last used as argument to `this.match` or
`this.matchSub`.
If the most recent call to `this.match` or `this.matchSub` did not
match anything, the result is unspecified.
If the global g modifier was in place for the matching, the position and
length of the leftmost substring is returned.
**/
public function matchedPos():{pos:Int, len:Int} {
return null;
}
/**
Tells if `this` regular expression matches a substring of String `s`.
This function expects `pos` and `len` to describe a valid substring of
`s`, or else the result is unspecified. To get more robust behavior,
`this.match(s.substr(pos,len))` can be used instead.
This method modifies the internal state.
If `s` is null, the result is unspecified.
**/
public function matchSub(s:String, pos:Int, len:Int = -1):Bool {
return false;
}
/**
Splits String `s` at all substrings `this` EReg matches.
If a match is found at the start of `s`, the result contains a leading
empty String "" entry.
If a match is found at the end of `s`, the result contains a trailing
empty String "" entry.
If two matching substrings appear next to each other, the result
contains the empty String `""` between them.
By default, this method splits `s` into two parts at the first matched
substring. If the global g modifier is in place, `s` is split at each
matched substring.
If `s` is null, the result is unspecified.
**/
public function split(s:String):Array<String> {
return null;
}
/**
Replaces the first substring of `s` which `this` EReg matches with `by`.
If `this` EReg does not match any substring, the result is `s`.
By default, this method replaces only the first matched substring. If
the global g modifier is in place, all matched substrings are replaced.
If `by` contains `$1` to `$9`, the digit corresponds to number of a
matched sub-group and its value is used instead. If no such sub-group
exists, the replacement is unspecified. The string `$$` becomes `$`.
If `s` or `by` are null, the result is unspecified.
**/
public function replace(s:String, by:String):String {
return null;
}
/**
Calls the function `f` for the substring of `s` which `this` EReg matches
and replaces that substring with the result of `f` call.
The `f` function takes `this` EReg object as its first argument and should
return a replacement string for the substring matched.
If `this` EReg does not match any substring, the result is `s`.
By default, this method replaces only the first matched substring. If
the global g modifier is in place, all matched substrings are replaced.
If `s` or `f` are null, the result is unspecified.
**/
public function map(s:String, f:EReg->String):String {
return null;
}
/**
Escape the string `s` for use as a part of regular expression.
If `s` is null, the result is unspecified.
**/
public static function escape(s:String):String {
return null;
}
}

View File

@ -0,0 +1,32 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/**
An abstract type that represents an Enum type.
The corresponding enum instance type is `EnumValue`.
See `Type` for the Haxe Reflection API.
@see https://haxe.org/manual/types-enum-instance.html
**/
@:coreType @:runtimeValue abstract Enum<T> {}

View File

@ -0,0 +1,61 @@
/*
* 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.
*/
/**
An abstract type that represents any enum value.
See `Type` for the Haxe Reflection API.
@see https://haxe.org/manual/types-enum-instance.html
**/
@:coreType abstract EnumValue {
/**
Matches enum instance `e` against pattern `pattern`, returning `true` if
matching succeeded and `false` otherwise.
Example usage:
```haxe
if (e.match(pattern)) {
// codeIfTrue
} else {
// codeIfFalse
}
```
This is equivalent to the following code:
```haxe
switch (e) {
case pattern:
// codeIfTrue
case _:
// codeIfFalse
}
```
This method is implemented in the compiler. This definition exists only
for documentation.
**/
public function match(pattern:Dynamic):Bool {
return false;
}
}

View File

@ -0,0 +1,65 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/**
IntIterator is used for implementing interval iterations.
It is usually not used explicitly, but through its special syntax:
`min...max`
While it is possible to assign an instance of IntIterator to a variable or
field, it is worth noting that IntIterator does not reset after being used
in a for-loop. Subsequent uses of the same instance will then have no
effect.
@see https://haxe.org/manual/lf-iterators.html
**/
class IntIterator {
var min:Int;
var max:Int;
/**
Iterates from `min` (inclusive) to `max` (exclusive).
If `max <= min`, the iterator will not act as a countdown.
**/
public inline function new(min:Int, max:Int) {
this.min = min;
this.max = max;
}
/**
Returns true if the iterator has other items, false otherwise.
**/
public inline function hasNext() {
return min < max;
}
/**
Moves to the next item of the iterator.
If this is called while hasNext() is false, the result is unspecified.
**/
public inline function next() {
return min++;
}
}

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.
*/
import haxe.ds.List;
/**
The `Lambda` class is a collection of methods to support functional
programming. It is ideally used with `using Lambda` and then acts as an
extension to Iterable types.
On static platforms, working with the Iterable structure might be slower
than performing the operations directly on known types, such as Array and
List.
If the first argument to any of the methods is null, the result is
unspecified.
@see https://haxe.org/manual/std-Lambda.html
**/
class Lambda {
/**
Creates an Array from Iterable `it`.
If `it` is an Array, this function returns a copy of it.
**/
public static function array<A>(it:Iterable<A>):Array<A> {
var a = new Array<A>();
for (i in it)
a.push(i);
return a;
}
/**
Creates a List form Iterable `it`.
If `it` is a List, this function returns a copy of it.
**/
public static function list<A>(it:Iterable<A>):List<A> {
var l = new List<A>();
for (i in it)
l.add(i);
return l;
}
/**
Creates a new Array by applying function `f` to all elements of `it`.
The order of elements is preserved.
If `f` is null, the result is unspecified.
**/
public static inline function map<A, B>(it:Iterable<A>, f:(item:A) -> B):Array<B> {
return [for (x in it) f(x)];
}
/**
Similar to map, but also passes the index of each element to `f`.
The order of elements is preserved.
If `f` is null, the result is unspecified.
**/
public static inline function mapi<A, B>(it:Iterable<A>, f:(index:Int, item:A) -> B):Array<B> {
var i = 0;
return [for (x in it) f(i++, x)];
}
/**
Concatenate a list of iterables.
The order of elements is preserved.
**/
public static inline function flatten<A>(it:Iterable<Iterable<A>>):Array<A> {
return [for (e in it) for (x in e) x];
}
/**
A composition of map and flatten.
The order of elements is preserved.
If `f` is null, the result is unspecified.
**/
public static inline function flatMap<A, B>(it:Iterable<A>, f:(item:A) -> Iterable<B>):Array<B> {
return Lambda.flatten(Lambda.map(it, f));
}
/**
Tells if `it` contains `elt`.
This function returns true as soon as an element is found which is equal
to `elt` according to the `==` operator.
If no such element is found, the result is false.
**/
public static function has<A>(it:Iterable<A>, elt:A):Bool {
for (x in it)
if (x == elt)
return true;
return false;
}
/**
Tells if `it` contains an element for which `f` is true.
This function returns true as soon as an element is found for which a
call to `f` returns true.
If no such element is found, the result is false.
If `f` is null, the result is unspecified.
**/
public static function exists<A>(it:Iterable<A>, f:(item:A) -> Bool) {
for (x in it)
if (f(x))
return true;
return false;
}
/**
Tells if `f` is true for all elements of `it`.
This function returns false as soon as an element is found for which a
call to `f` returns false.
If no such element is found, the result is true.
In particular, this function always returns true if `it` is empty.
If `f` is null, the result is unspecified.
**/
public static function foreach<A>(it:Iterable<A>, f:(item:A) -> Bool) {
for (x in it)
if (!f(x))
return false;
return true;
}
/**
Calls `f` on all elements of `it`, in order.
If `f` is null, the result is unspecified.
**/
public static function iter<A>(it:Iterable<A>, f:(item:A) -> Void) {
for (x in it)
f(x);
}
/**
Returns a Array containing those elements of `it` for which `f` returned
true.
If `it` is empty, the result is the empty Array even if `f` is null.
Otherwise if `f` is null, the result is unspecified.
**/
public static function filter<A>(it:Iterable<A>, f:(item:A) -> Bool) {
return [for (x in it) if (f(x)) x];
}
/**
Functional fold on Iterable `it`, using function `f` with start argument
`first`.
If `it` has no elements, the result is `first`.
Otherwise the first element of `it` is passed to `f` alongside `first`.
The result of that call is then passed to `f` with the next element of
`it`, and so on until `it` has no more elements.
If `it` or `f` are null, the result is unspecified.
**/
public static function fold<A, B>(it:Iterable<A>, f:(item:A, result:B) -> B, first:B):B {
for (x in it)
first = f(x, first);
return first;
}
/**
Similar to fold, but also passes the index of each element to `f`.
If `it` or `f` are null, the result is unspecified.
**/
public static function foldi<A, B>(it:Iterable<A>, f:(item:A, result:B, index:Int) -> B, first:B):B {
var i = 0;
for (x in it) {
first = f(x, first, i);
++i;
}
return first;
}
/**
Returns the number of elements in `it` for which `pred` is true, or the
total number of elements in `it` if `pred` is null.
This function traverses all elements.
**/
public static function count<A>(it:Iterable<A>, ?pred:(item:A) -> Bool) {
var n = 0;
if (pred == null)
for (_ in it)
n++;
else
for (x in it)
if (pred(x))
n++;
return n;
}
/**
Tells if Iterable `it` does not contain any element.
**/
public static function empty<T>(it:Iterable<T>):Bool {
return !it.iterator().hasNext();
}
/**
Returns the index of the first element `v` within Iterable `it`.
This function uses operator `==` to check for equality.
If `v` does not exist in `it`, the result is -1.
**/
public static function indexOf<T>(it:Iterable<T>, v:T):Int {
var i = 0;
for (v2 in it) {
if (v == v2)
return i;
i++;
}
return -1;
}
/**
Returns the first element of `it` for which `f` is true.
This function returns as soon as an element is found for which a call to
`f` returns true.
If no such element is found, the result is null.
If `f` is null, the result is unspecified.
**/
public static function find<T>(it:Iterable<T>, f:(item:T) -> Bool):Null<T> {
for (v in it) {
if (f(v))
return v;
}
return null;
}
/**
Returns the index of the first element of `it` for which `f` is true.
This function returns as soon as an element is found for which a call to
`f` returns true.
If no such element is found, the result is -1.
If `f` is null, the result is unspecified.
**/
public static function findIndex<T>(it:Iterable<T>, f:(item:T) -> Bool):Int {
var i = 0;
for (v in it) {
if (f(v))
return i;
i++;
}
return -1;
}
/**
Returns a new Array containing all elements of Iterable `a` followed by
all elements of Iterable `b`.
If `a` or `b` are null, the result is unspecified.
**/
public static function concat<T>(a:Iterable<T>, b:Iterable<T>):Array<T> {
var l = new Array();
for (x in a)
l.push(x);
for (x in b)
l.push(x);
return l;
}
}

View File

@ -0,0 +1,22 @@
/*
* 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.
*/
typedef List<T> = haxe.ds.List<T>;

View File

@ -0,0 +1,26 @@
/*
* 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.
*/
typedef Map<K, V> = haxe.ds.Map<K, V>;
@:dox(hide)
@:deprecated
typedef IMap<K, V> = haxe.Constraints.IMap<K, V>;

View File

@ -0,0 +1,309 @@
/*
* 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.
*/
/**
This class defines mathematical functions and constants.
@see https://haxe.org/manual/std-math.html
**/
#if cpp
@:include("hxMath.h")
#end
@:pure
extern class Math {
/**
Represents the ratio of the circumference of a circle to its diameter,
specified by the constant, π. `PI` is approximately `3.141592653589793`.
**/
static var PI(default, null):Float;
/**
A special `Float` constant which denotes negative infinity.
For example, this is the result of `-1.0 / 0.0`.
Operations with `NEGATIVE_INFINITY` as an operand may result in
`NEGATIVE_INFINITY`, `POSITIVE_INFINITY` or `NaN`.
If this constant is converted to an `Int`, e.g. through `Std.int()`, the
result is unspecified.
**/
static var NEGATIVE_INFINITY(default, null):Float;
/**
A special `Float` constant which denotes positive infinity.
For example, this is the result of `1.0 / 0.0`.
Operations with `POSITIVE_INFINITY` as an operand may result in
`NEGATIVE_INFINITY`, `POSITIVE_INFINITY` or `NaN`.
If this constant is converted to an `Int`, e.g. through `Std.int()`, the
result is unspecified.
**/
static var POSITIVE_INFINITY(default, null):Float;
/**
A special `Float` constant which denotes an invalid number.
`NaN` stands for "Not a Number". It occurs when a mathematically incorrect
operation is executed, such as taking the square root of a negative
number: `Math.sqrt(-1)`.
All further operations with `NaN` as an operand will result in `NaN`.
If this constant is converted to an `Int`, e.g. through `Std.int()`, the
result is unspecified.
In order to test if a value is `NaN`, you should use `Math.isNaN()` function.
**/
static var NaN(default, null):Float;
/**
Returns the absolute value of `v`.
- If `v` is positive or `0`, the result is unchanged. Otherwise the result is `-v`.
- If `v` is `NEGATIVE_INFINITY` or `POSITIVE_INFINITY`, the result is `POSITIVE_INFINITY`.
- If `v` is `NaN`, the result is `NaN`.
**/
static function abs(v:Float):Float;
/**
Returns the smaller of values `a` and `b`.
- If `a` or `b` are `NaN`, the result is `NaN`.
- If `a` or `b` are `NEGATIVE_INFINITY`, the result is `NEGATIVE_INFINITY`.
- If `a` and `b` are `POSITIVE_INFINITY`, the result is `POSITIVE_INFINITY`.
**/
static function min(a:Float, b:Float):Float;
/**
Returns the greater of values `a` and `b`.
- If `a` or `b` are `NaN`, the result is `NaN`.
- If `a` or `b` are `POSITIVE_INFINITY`, the result is `POSITIVE_INFINITY`.
- If `a` and `b` are `NEGATIVE_INFINITY`, the result is `NEGATIVE_INFINITY`.
**/
static function max(a:Float, b:Float):Float;
/**
Returns the trigonometric sine of the specified angle `v`, in radians.
If `v` is `NaN` or infinite, the result is `NaN`.
**/
static function sin(v:Float):Float;
/**
Returns the trigonometric cosine of the specified angle `v`, in radians.
If `v` is `NaN` or infinite, the result is `NaN`.
**/
static function cos(v:Float):Float;
/**
Returns the trigonometric tangent of the specified angle `v`, in radians.
If `v` is `NaN` or infinite, the result is `NaN`.
**/
static function tan(v:Float):Float;
/**
Returns the trigonometric arc of the specified angle `v`, in radians.
If `v` is `NaN` or infinite, the result is `NaN`.
**/
static function asin(v:Float):Float;
/**
Returns the trigonometric arc cosine of the specified angle `v`,
in radians.
If `v` is `NaN` or infinite, the result is `NaN`.
**/
static function acos(v:Float):Float;
/**
Returns the trigonometric arc tangent of the specified angle `v`,
in radians.
If `v` is `NaN` or infinite, the result is `NaN`.
**/
static function atan(v:Float):Float;
/**
Returns the trigonometric arc tangent whose tangent is the quotient of
two specified numbers, in radians.
If parameter `x` or `y` is `NaN`, `NEGATIVE_INFINITY` or `POSITIVE_INFINITY`,
the result is `NaN`.
**/
static function atan2(y:Float, x:Float):Float;
/**
Returns Euler's number, raised to the power of `v`.
`exp(1.0)` is approximately `2.718281828459`.
- If `v` is `POSITIVE_INFINITY`, the result is `POSITIVE_INFINITY`.
- If `v` is `NEGATIVE_INFINITY`, the result is `0.0`.
- If `v` is `NaN`, the result is `NaN`.
**/
static function exp(v:Float):Float;
/**
Returns the natural logarithm of `v`.
This is the mathematical inverse operation of exp,
i.e. `log(exp(v)) == v` always holds.
- If `v` is negative (including `NEGATIVE_INFINITY`) or `NaN`, the result is `NaN`.
- If `v` is `POSITIVE_INFINITY`, the result is `POSITIVE_INFINITY`.
- If `v` is `0.0`, the result is `NEGATIVE_INFINITY`.
**/
static function log(v:Float):Float;
/**
Returns a specified base `v` raised to the specified power `exp`.
**/
static function pow(v:Float, exp:Float):Float;
/**
Returns the square root of `v`.
- If `v` is negative (including `NEGATIVE_INFINITY`) or `NaN`, the result is `NaN`.
- If `v` is `POSITIVE_INFINITY`, the result is `POSITIVE_INFINITY`.
- If `v` is `0.0`, the result is `0.0`.
**/
static function sqrt(v:Float):Float;
/**
Rounds `v` to the nearest integer value.
Ties are rounded up, so that `0.5` becomes `1` and `-0.5` becomes `0`.
If `v` is outside of the signed `Int32` range, or is `NaN`, `NEGATIVE_INFINITY`
or `POSITIVE_INFINITY`, the result is unspecified.
**/
static function round(v:Float):Int;
/**
Returns the largest integer value that is not greater than `v`.
If `v` is outside of the signed `Int32` range, or is `NaN`, `NEGATIVE_INFINITY`
or `POSITIVE_INFINITY`, the result is unspecified.
**/
static function floor(v:Float):Int;
/**
Returns the smallest integer value that is not less than `v`.
If `v` is outside of the signed `Int32` range, or is `NaN`, `NEGATIVE_INFINITY`
or `POSITIVE_INFINITY`, the result is unspecified.
**/
static function ceil(v:Float):Int;
/**
Returns a pseudo-random number which is greater than or equal to `0.0`,
and less than `1.0`.
**/
static function random():Float;
#if (flash || cpp || eval)
/**
Returns the largest integer value that is not greater than `v`, as a `Float`.
If `v` is is `NaN`, `NEGATIVE_INFINITY` or `POSITIVE_INFINITY`,
the result is unspecified.
**/
static function ffloor(v:Float):Float;
/**
Returns the smallest integer value that is not less than `v`, as a `Float`.
If `v` is is `NaN`, `NEGATIVE_INFINITY` or `POSITIVE_INFINITY`,
the result is unspecified.
**/
static function fceil(v:Float):Float;
/**
Rounds `v` to the nearest integer value, as a Float.
Ties are rounded up, so that `0.5` becomes `1` and `-0.5` becomes `0`.
If `v` is is `NaN`, `NEGATIVE_INFINITY` or `POSITIVE_INFINITY`,
the result is unspecified.
**/
static function fround(v:Float):Float;
#else
static inline function ffloor(v:Float):Float {
return floor(v);
}
static inline function fceil(v:Float):Float {
return ceil(v);
}
static inline function fround(v:Float):Float {
return round(v);
}
#end
/**
Tells if `f` is a finite number.
If `f` is `POSITIVE_INFINITY`, `NEGATIVE_INFINITY` or `NaN`, the result
is `false`, otherwise the result is `true`.
**/
static function isFinite(f:Float):Bool;
/**
Tells if `f` is not a valid number.
If `f` is `NaN`, the result is `true`, otherwise the result is `false`.
In particular, both `POSITIVE_INFINITY` and `NEGATIVE_INFINITY` are
not considered `NaN`.
**/
static function isNaN(f:Float):Bool;
#if !eval
private static function __init__():Void
untyped {
#if flash
NaN = __global__["Number"].NaN;
NEGATIVE_INFINITY = __global__["Number"].NEGATIVE_INFINITY;
POSITIVE_INFINITY = __global__["Number"].POSITIVE_INFINITY;
#else
// TODO: Abandoned code block? Js has its own _std/Math.hx
Math.__name__ = ["Math"];
Math.NaN = Number["NaN"];
Math.NEGATIVE_INFINITY = Number["NEGATIVE_INFINITY"];
Math.POSITIVE_INFINITY = Number["POSITIVE_INFINITY"];
#end
Math.isFinite = function(i) {
return #if flash __global__["isFinite"](i); #else false; #end
};
Math.isNaN = function(i) {
return #if flash __global__["isNaN"](i); #else false; #end
};
}
#end
}

View File

@ -0,0 +1,202 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/**
The Reflect API is a way to manipulate values dynamically through an
abstract interface in an untyped manner. Use with care.
@see https://haxe.org/manual/std-reflection.html
**/
extern class Reflect {
/**
Tells if structure `o` has a field named `field`.
This is only guaranteed to work for anonymous structures. Refer to
`Type.getInstanceFields` for a function supporting class instances.
If `o` or `field` are null, the result is unspecified.
**/
static function hasField(o:Dynamic, field:String):Bool;
/**
Returns the value of the field named `field` on object `o`.
If `o` is not an object or has no field named `field`, the result is
null.
If the field is defined as a property, its accessors are ignored. Refer
to `Reflect.getProperty` for a function supporting property accessors.
If `field` is null, the result is unspecified.
**/
static function field(o:Dynamic, field:String):Dynamic;
/**
Sets the field named `field` of object `o` to value `value`.
If `o` has no field named `field`, this function is only guaranteed to
work for anonymous structures.
If `o` or `field` are null, the result is unspecified.
**/
static function setField(o:Dynamic, field:String, value:Dynamic):Void;
/**
Returns the value of the field named `field` on object `o`, taking
property getter functions into account.
If the field is not a property, this function behaves like
`Reflect.field`, but might be slower.
If `o` or `field` are null, the result is unspecified.
**/
static function getProperty(o:Dynamic, field:String):Dynamic;
/**
Sets the field named `field` of object `o` to value `value`, taking
property setter functions into account.
If the field is not a property, this function behaves like
`Reflect.setField`, but might be slower.
If `field` is null, the result is unspecified.
**/
static function setProperty(o:Dynamic, field:String, value:Dynamic):Void;
/**
Call a method `func` with the given arguments `args`.
The object `o` is ignored in most cases. It serves as the `this`-context in the following
situations:
* (neko) Allows switching the context to `o` in all cases.
* (macro) Same as neko for Haxe 3. No context switching in Haxe 4.
* (js, lua) Require the `o` argument if `func` does not, but should have a context.
This can occur by accessing a function field natively, e.g. through `Reflect.field`
or by using `(object : Dynamic).field`. However, if `func` has a context, `o` is
ignored like on other targets.
**/
static function callMethod(o:Dynamic, func:haxe.Constraints.Function, args:Array<Dynamic>):Dynamic;
/**
Returns the fields of structure `o`.
This method is only guaranteed to work on anonymous structures. Refer to
`Type.getInstanceFields` for a function supporting class instances.
If `o` is null, the result is unspecified.
**/
static function fields(o:Dynamic):Array<String>;
/**
Returns true if `f` is a function, false otherwise.
If `f` is null, the result is false.
**/
static function isFunction(f:Dynamic):Bool;
/**
Compares `a` and `b`.
If `a` is less than `b`, the result is negative. If `b` is less than
`a`, the result is positive. If `a` and `b` are equal, the result is 0.
This function is only defined if `a` and `b` are of the same type.
If that type is a function, the result is unspecified and
`Reflect.compareMethods` should be used instead.
For all other types, the result is 0 if `a` and `b` are equal. If they
are not equal, the result depends on the type and is negative if:
- Numeric types: a is less than b
- String: a is lexicographically less than b
- Other: unspecified
If `a` and `b` are null, the result is 0. If only one of them is null,
the result is unspecified.
**/
static function compare<T>(a:T, b:T):Int;
/**
Compares the functions `f1` and `f2`.
If `f1` or `f2` are null, the result is false.
If `f1` or `f2` are not functions, the result is unspecified.
Otherwise the result is true if `f1` and the `f2` are physically equal,
false otherwise.
If `f1` or `f2` are member method closures, the result is true if they
are closures of the same method on the same object value, false otherwise.
**/
static function compareMethods(f1:Dynamic, f2:Dynamic):Bool;
/**
Tells if `v` is an object.
The result is true if `v` is one of the following:
- class instance
- structure
- `Class<T>`
- `Enum<T>`
Otherwise, including if `v` is null, the result is false.
**/
static function isObject(v:Dynamic):Bool;
/**
Tells if `v` is an enum value.
The result is true if `v` is of type EnumValue, i.e. an enum
constructor.
Otherwise, including if `v` is null, the result is false.
**/
static function isEnumValue(v:Dynamic):Bool;
/**
Removes the field named `field` from structure `o`.
This method is only guaranteed to work on anonymous structures.
If `o` or `field` are null, the result is unspecified.
**/
static function deleteField(o:Dynamic, field:String):Bool;
/**
Copies the fields of structure `o`.
This is only guaranteed to work on anonymous structures.
If `o` is null, the result is `null`.
**/
static function copy<T>(o:Null<T>):Null<T>;
/**
Transform a function taking an array of arguments into a function that can
be called with any number of arguments.
**/
@:overload(function(f:Array<Dynamic>->Void):Dynamic {})
static function makeVarArgs(f:Array<Dynamic>->Dynamic):Dynamic;
}

View File

@ -0,0 +1,134 @@
/*
* 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.
*/
#if !(core_api || cross || eval)
#error "Please don't add haxe/std to your classpath, instead set HAXE_STD_PATH env var"
#end
/**
The Std class provides standard methods for manipulating basic types.
**/
extern class Std {
/**
DEPRECATED. Use `Std.isOfType(v, t)` instead.
Tells if a value `v` is of the type `t`. Returns `false` if `v` or `t` are null.
If `t` is a class or interface with `@:generic` meta, the result is `false`.
**/
@:deprecated('Std.is is deprecated. Use Std.isOfType instead.')
static function is(v:Dynamic, t:Dynamic):Bool;
/**
Tells if a value `v` is of the type `t`. Returns `false` if `v` or `t` are null.
If `t` is a class or interface with `@:generic` meta, the result is `false`.
**/
static function isOfType(v:Dynamic, t:Dynamic):Bool;
/**
Checks if object `value` is an instance of class or interface `c`.
Compiles only if the type specified by `c` can be assigned to the type
of `value`.
This method checks if a downcast is possible. That is, if the runtime
type of `value` is assignable to the type specified by `c`, `value` is
returned. Otherwise null is returned.
This method is not guaranteed to work with core types such as `String`,
`Array` and `Date`.
If `value` is null, the result is null. If `c` is null, the result is
unspecified.
**/
static function downcast<T:{}, S:T>(value:T, c:Class<S>):S;
@:deprecated('Std.instance() is deprecated. Use Std.downcast() instead.')
static function instance<T:{}, S:T>(value:T, c:Class<S>):S;
/**
Converts any value to a String.
If `s` is of `String`, `Int`, `Float` or `Bool`, its value is returned.
If `s` is an instance of a class and that class or one of its parent classes has
a `toString` method, that method is called. If no such method is present, the result
is unspecified.
If `s` is an enum constructor without argument, the constructor's name is returned. If
arguments exists, the constructor's name followed by the String representations of
the arguments is returned.
If `s` is a structure, the field names along with their values are returned. The field order
and the operator separating field names and values are unspecified.
If s is null, "null" is returned.
**/
static function string(s:Dynamic):String;
/**
Converts a `Float` to an `Int`, rounded towards 0.
If `x` is outside of the signed Int32 range, or is `NaN`, `NEGATIVE_INFINITY` or `POSITIVE_INFINITY`, the result is unspecified.
**/
static function int(x:Float):Int;
/**
Converts a `String` to an `Int`.
Leading whitespaces are ignored.
If `x` starts with 0x or 0X, hexadecimal notation is recognized where the following digits may
contain 0-9 and A-F.
Otherwise `x` is read as decimal number with 0-9 being allowed characters. `x` may also start with
a - to denote a negative value.
In decimal mode, parsing continues until an invalid character is detected, in which case the
result up to that point is returned. For hexadecimal notation, the effect of invalid characters
is unspecified.
Leading 0s that are not part of the 0x/0X hexadecimal notation are ignored, which means octal
notation is not supported.
If `x` is null, the result is unspecified.
If `x` cannot be parsed as integer, the result is `null`.
**/
static function parseInt(x:String):Null<Int>;
/**
Converts a `String` to a `Float`.
The parsing rules for `parseInt` apply here as well, with the exception of invalid input
resulting in a `NaN` value instead of null.
Additionally, decimal notation may contain a single `.` to denote the start of the fractions.
**/
static function parseFloat(x:String):Float;
/**
Return a random integer between 0 included and `x` excluded.
If `x <= 1`, the result is always 0.
**/
static function random(x:Int):Int;
}

View File

@ -0,0 +1,172 @@
/*
* 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.
*/
// standard Haxe types
/**
The standard `Void` type. Only `null` values can be of the type `Void`.
@see https://haxe.org/manual/types-void.html
**/
#if jvm
@:runtimeValue
#end
@:coreType abstract Void {}
/**
The standard `Float` type, this is a double-precision IEEE 64bit float.
On static targets, `null` cannot be assigned to Float. If this is necessary,
`Null<Float>` can be used instead.
`Std.int` converts a `Float` to an `Int`, rounded towards 0.
`Std.parseFloat` converts a `String` to a `Float`.
@see https://haxe.org/manual/types-basic-types.html
@see https://haxe.org/manual/types-nullability.html
**/
@:coreType @:notNull @:runtimeValue abstract Float {}
/**
The standard `Int` type. Its precision depends on the platform.
On static targets, `null` cannot be assigned to `Int`. If this is necessary,
`Null<Int>` can be used instead.
`Std.int` converts a `Float` to an `Int`, rounded towards 0.
`Std.parseInt` converts a `String` to an `Int`.
@see https://haxe.org/manual/types-basic-types.html
@see https://haxe.org/manual/std-math-integer-math.html
@see https://haxe.org/manual/types-nullability.html
**/
@:coreType @:notNull @:runtimeValue abstract Int to Float {}
#if (java || cs || hl || cpp)
/**
Single-precision IEEE 32bit float (4-byte).
**/
@:coreType @:notNull @:runtimeValue abstract Single to Float from Float {}
#end
/**
`Null<T>` is a wrapper that can be used to make the basic types `Int`,
`Float` and `Bool` nullable on static targets.
If null safety is enabled, only types wrapped in `Null<T>` are nullable.
Otherwise, it has no effect on non-basic-types, but it can be useful as a way to document
that `null` is an acceptable value for a method argument, return value or variable.
@see https://haxe.org/manual/types-nullability.html
**/
@:forward
@:coreType
abstract Null<T> from T to T {}
/**
The standard Boolean type, which can either be `true` or `false`.
On static targets, `null` cannot be assigned to `Bool`. If this is necessary,
`Null<Bool>` can be used instead.
@see https://haxe.org/manual/types-bool.html
@see https://haxe.org/manual/types-nullability.html
**/
@:coreType @:notNull @:runtimeValue abstract Bool {}
/**
`Dynamic` is a special type which is compatible with all other types.
Use of `Dynamic` should be minimized as it prevents several compiler
checks and optimizations. See `Any` type for a safer alternative for
representing values of any type.
@see https://haxe.org/manual/types-dynamic.html
**/
@:coreType @:runtimeValue abstract Dynamic<T> {}
/**
An `Iterator` is a structure that permits iteration over elements of type `T`.
Any class with matching `hasNext()` and `next()` fields is considered an `Iterator`
and can then be used e.g. in `for`-loops. This makes it easy to implement
custom iterators.
@see https://haxe.org/manual/lf-iterators.html
**/
typedef Iterator<T> = {
/**
Returns `false` if the iteration is complete, `true` otherwise.
Usually iteration is considered to be complete if all elements of the
underlying data structure were handled through calls to `next()`. However,
in custom iterators any logic may be used to determine the completion
state.
**/
function hasNext():Bool;
/**
Returns the current item of the `Iterator` and advances to the next one.
This method is not required to check `hasNext()` first. A call to this
method while `hasNext()` is `false` yields unspecified behavior.
On the other hand, iterators should not require a call to `hasNext()`
before the first call to `next()` if an element is available.
**/
function next():T;
}
/**
An `Iterable` is a data structure which has an `iterator()` method.
See `Lambda` for generic functions on iterable structures.
@see https://haxe.org/manual/lf-iterators.html
**/
typedef Iterable<T> = {
function iterator():Iterator<T>;
}
/**
A `KeyValueIterator` is an `Iterator` that has a key and a value.
**/
typedef KeyValueIterator<K, V> = Iterator<{key:K, value:V}>;
/**
A `KeyValueIterable` is a data structure which has a `keyValueIterator()`
method to iterate over key-value-pairs.
**/
typedef KeyValueIterable<K, V> = {
function keyValueIterator():KeyValueIterator<K, V>;
}
/**
`ArrayAccess` is used to indicate a class that can be accessed using brackets.
The type parameter represents the type of the elements stored.
This interface should be used for externs only. Haxe does not support custom
array access on classes. However, array access can be implemented for
abstract types.
@see https://haxe.org/manual/types-abstract-array-access.html
**/
extern interface ArrayAccess<T> {}

View File

@ -0,0 +1,175 @@
/*
* 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.
*/
/**
The basic String class.
A Haxe String is immutable, it is not possible to modify individual
characters. No method of this class changes the state of `this` String.
Strings can be constructed using the String literal syntax `"string value"`.
String can be concatenated by using the `+` operator. If an operand is not a
String, it is passed through `Std.string()` first.
@see https://haxe.org/manual/std-String.html
**/
extern class String {
/**
The number of characters in `this` String.
**/
var length(default, null):Int;
/**
Creates a copy from a given String.
**/
function new(string:String):Void;
/**
Returns a String where all characters of `this` String are upper case.
**/
function toUpperCase():String;
/**
Returns a String where all characters of `this` String are lower case.
**/
function toLowerCase():String;
/**
Returns the character at position `index` of `this` String.
If `index` is negative or exceeds `this.length`, the empty String `""`
is returned.
**/
function charAt(index:Int):String;
/**
Returns the character code at position `index` of `this` String.
If `index` is negative or exceeds `this.length`, `null` is returned.
To obtain the character code of a single character, `"x".code` can be
used instead to inline the character code at compile time. Note that
this only works on String literals of length 1.
**/
function charCodeAt(index:Int):Null<Int>;
/**
Returns the position of the leftmost occurrence of `str` within `this`
String.
If `startIndex` is given, the search is performed within the substring
of `this` String starting from `startIndex`.
If `startIndex` exceeds `this.length`, -1 is returned.
If `startIndex` is negative, the result is unspecifed.
Otherwise the search is performed within `this` String. In either case,
the returned position is relative to the beginning of `this` String.
If `str` cannot be found, -1 is returned.
**/
function indexOf(str:String, ?startIndex:Int):Int;
/**
Returns the position of the rightmost occurrence of `str` within `this`
String.
If `startIndex` is given, the search is performed within the substring
of `this` String from 0 to `startIndex + str.length`. Otherwise the search
is performed within `this` String. In either case, the returned position
is relative to the beginning of `this` String.
If `startIndex` is negative, the result is unspecifed.
If `str` cannot be found, -1 is returned.
**/
function lastIndexOf(str:String, ?startIndex:Int):Int;
/**
Splits `this` String at each occurrence of `delimiter`.
If `this` String is the empty String `""`, the result is not consistent
across targets and may either be `[]` (on Js, Cpp) or `[""]`.
If `delimiter` is the empty String `""`, `this` String is split into an
Array of `this.length` elements, where the elements correspond to the
characters of `this` String.
If `delimiter` is not found within `this` String, the result is an Array
with one element, which equals `this` String.
If `delimiter` is null, the result is unspecified.
Otherwise, `this` String is split into parts at each occurrence of
`delimiter`. If `this` String starts (or ends) with `delimiter`, the
result `Array` contains a leading (or trailing) empty String `""` element.
Two subsequent delimiters also result in an empty String `""` element.
**/
function split(delimiter:String):Array<String>;
/**
Returns `len` characters of `this` String, starting at position `pos`.
If `len` is omitted, all characters from position `pos` to the end of
`this` String are included.
If `pos` is negative, its value is calculated from the end of `this`
String by `this.length + pos`. If this yields a negative value, 0 is
used instead.
If the calculated position + `len` exceeds `this.length`, the characters
from that position to the end of `this` String are returned.
If `len` is negative, the result is unspecified.
**/
function substr(pos:Int, ?len:Int):String;
/**
Returns the part of `this` String from `startIndex` to but not including `endIndex`.
If `startIndex` or `endIndex` are negative, 0 is used instead.
If `startIndex` exceeds `endIndex`, they are swapped.
If the (possibly swapped) `endIndex` is omitted or exceeds
`this.length`, `this.length` is used instead.
If the (possibly swapped) `startIndex` exceeds `this.length`, the empty
String `""` is returned.
**/
function substring(startIndex:Int, ?endIndex:Int):String;
/**
Returns the String itself.
**/
function toString():String;
/**
Returns the String corresponding to the character code `code`.
If `code` is negative or has another invalid value, the result is
unspecified.
**/
@:pure static function fromCharCode(code:Int):String;
}

View File

@ -0,0 +1,99 @@
/*
* 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.
*/
/**
A String buffer is an efficient way to build a big string by appending small
elements together.
Unlike String, an instance of StringBuf is not immutable in the sense that
it can be passed as argument to functions which modify it by appending more
values.
**/
class StringBuf {
var b:String;
/**
The length of `this` StringBuf in characters.
**/
public var length(get, never):Int;
/**
Creates a new StringBuf instance.
This may involve initialization of the internal buffer.
**/
public inline function new() {
b = "";
}
inline function get_length():Int {
return b.length;
}
/**
Appends the representation of `x` to `this` StringBuf.
The exact representation of `x` may vary per platform. To get more
consistent behavior, this function should be called with
Std.string(x).
If `x` is null, the String "null" is appended.
**/
public inline function add<T>(x:T):Void {
b += x;
}
/**
Appends the character identified by `c` to `this` StringBuf.
If `c` is negative or has another invalid value, the result is
unspecified.
**/
public inline function addChar(c:Int):Void {
b += String.fromCharCode(c);
}
/**
Appends a substring of `s` to `this` StringBuf.
This function expects `pos` and `len` to describe a valid substring of
`s`, or else the result is unspecified. To get more robust behavior,
`this.add(s.substr(pos,len))` can be used instead.
If `s` or `pos` are null, the result is unspecified.
If `len` is omitted or null, the substring ranges from `pos` to the end
of `s`.
**/
public inline function addSub(s:String, pos:Int, ?len:Int):Void {
b += (len == null ? s.substr(pos) : s.substr(pos, len));
}
/**
Returns the content of `this` StringBuf as String.
The buffer is not emptied by this operation.
**/
public inline function toString():String {
return b;
}
}

View File

@ -0,0 +1,640 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
import haxe.iterators.StringIterator;
import haxe.iterators.StringKeyValueIterator;
#if cpp
using cpp.NativeString;
#end
/**
This class provides advanced methods on Strings. It is ideally used with
`using StringTools` and then acts as an [extension](https://haxe.org/manual/lf-static-extension.html)
to the `String` class.
If the first argument to any of the methods is null, the result is
unspecified.
**/
class StringTools {
/**
Encode an URL by using the standard format.
**/
#if (!java && !cpp && !lua && !eval) inline #end public static function urlEncode(s:String):String {
#if flash
return untyped __global__["encodeURIComponent"](s);
#elseif neko
return untyped new String(_urlEncode(s.__s));
#elseif js
return untyped encodeURIComponent(s);
#elseif cpp
return untyped s.__URLEncode();
#elseif java
return postProcessUrlEncode(java.net.URLEncoder.encode(s, "UTF-8"));
#elseif cs
return untyped cs.system.Uri.EscapeDataString(s);
#elseif python
return python.lib.urllib.Parse.quote(s, "");
#elseif hl
var len = 0;
var b = @:privateAccess s.bytes.urlEncode(len);
return @:privateAccess String.__alloc__(b, len);
#elseif lua
s = lua.NativeStringTools.gsub(s, "\n", "\r\n");
s = lua.NativeStringTools.gsub(s, "([^%w %-%_%.%~])", function(c) {
return lua.NativeStringTools.format("%%%02X", lua.NativeStringTools.byte(c) + '');
});
s = lua.NativeStringTools.gsub(s, " ", "+");
return s;
#else
return null;
#end
}
#if java
private static function postProcessUrlEncode(s:String):String {
var ret = new StringBuf();
var i = 0, len = s.length;
while (i < len) {
switch (_charAt(s, i++)) {
case '+'.code:
ret.add('%20');
case '%'.code if (i <= len - 2):
var c1 = _charAt(s, i++), c2 = _charAt(s, i++);
switch [c1, c2] {
case ['2'.code, '1'.code]:
ret.addChar('!'.code);
case ['2'.code, '7'.code]:
ret.addChar('\''.code);
case ['2'.code, '8'.code]:
ret.addChar('('.code);
case ['2'.code, '9'.code]:
ret.addChar(')'.code);
case ['7'.code, 'E'.code] | ['7'.code, 'e'.code]:
ret.addChar('~'.code);
case _:
ret.addChar('%'.code);
ret.addChar(cast c1);
ret.addChar(cast c2);
}
case var chr:
ret.addChar(cast chr);
}
}
return ret.toString();
}
#end
/**
Decode an URL using the standard format.
**/
#if (!java && !cpp && !lua && !eval) inline #end public static function urlDecode(s:String):String {
#if flash
return untyped __global__["decodeURIComponent"](s.split("+").join(" "));
#elseif neko
return untyped new String(_urlDecode(s.__s));
#elseif js
return untyped decodeURIComponent(s.split("+").join(" "));
#elseif cpp
return untyped s.__URLDecode();
#elseif java
try
return java.net.URLDecoder.decode(s, "UTF-8")
catch (e:Dynamic)
throw e;
#elseif cs
return untyped cs.system.Uri.UnescapeDataString(s);
#elseif python
return python.lib.urllib.Parse.unquote(s);
#elseif hl
var len = 0;
var b = @:privateAccess s.bytes.urlDecode(len);
return @:privateAccess String.__alloc__(b, len);
#elseif lua
s = lua.NativeStringTools.gsub(s, "+", " ");
s = lua.NativeStringTools.gsub(s, "%%(%x%x)", function(h) {
return lua.NativeStringTools.char(lua.Lua.tonumber(h, 16));
});
s = lua.NativeStringTools.gsub(s, "\r\n", "\n");
return s;
#else
return null;
#end
}
/**
Escapes HTML special characters of the string `s`.
The following replacements are made:
- `&` becomes `&amp`;
- `<` becomes `&lt`;
- `>` becomes `&gt`;
If `quotes` is true, the following characters are also replaced:
- `"` becomes `&quot`;
- `'` becomes `&#039`;
**/
public static function htmlEscape(s:String, ?quotes:Bool):String {
var buf = new StringBuf();
for (code in #if neko iterator(s) #else new haxe.iterators.StringIteratorUnicode(s) #end) {
switch (code) {
case '&'.code:
buf.add("&amp;");
case '<'.code:
buf.add("&lt;");
case '>'.code:
buf.add("&gt;");
case '"'.code if (quotes):
buf.add("&quot;");
case '\''.code if (quotes):
buf.add("&#039;");
case _:
buf.addChar(code);
}
}
return buf.toString();
}
/**
Unescapes HTML special characters of the string `s`.
This is the inverse operation to htmlEscape, i.e. the following always
holds: `htmlUnescape(htmlEscape(s)) == s`
The replacements follow:
- `&amp;` becomes `&`
- `&lt;` becomes `<`
- `&gt;` becomes `>`
- `&quot;` becomes `"`
- `&#039;` becomes `'`
**/
public static function htmlUnescape(s:String):String {
return s.split("&gt;")
.join(">")
.split("&lt;")
.join("<")
.split("&quot;")
.join('"')
.split("&#039;")
.join("'")
.split("&amp;")
.join("&");
}
/**
Returns `true` if `s` contains `value` and `false` otherwise.
When `value` is `null`, the result is unspecified.
**/
public static inline function contains(s:String, value:String):Bool {
#if (js && js_es >= 6)
return (cast s).includes(value);
#else
return s.indexOf(value) != -1;
#end
}
/**
Tells if the string `s` starts with the string `start`.
If `start` is `null`, the result is unspecified.
If `start` is the empty String `""`, the result is true.
**/
public static #if (cs || java || python || (js && js_es >= 6)) inline #end function startsWith(s:String, start:String):Bool {
#if java
return (cast s : java.NativeString).startsWith(start);
#elseif cs
return untyped s.StartsWith(start);
#elseif hl
return @:privateAccess (s.length >= start.length && s.bytes.compare(0, start.bytes, 0, start.length << 1) == 0);
#elseif python
return python.NativeStringTools.startswith(s, start);
#elseif (js && js_es >= 6)
return (cast s).startsWith(start);
#else
return (s.length >= start.length && s.lastIndexOf(start, 0) == 0);
#end
}
/**
Tells if the string `s` ends with the string `end`.
If `end` is `null`, the result is unspecified.
If `end` is the empty String `""`, the result is true.
**/
public static #if (cs || java || python || (js && js_es >= 6)) inline #end function endsWith(s:String, end:String):Bool {
#if java
return (cast s : java.NativeString).endsWith(end);
#elseif cs
return untyped s.EndsWith(end);
#elseif hl
var elen = end.length;
var slen = s.length;
return @:privateAccess (slen >= elen && s.bytes.compare((slen - elen) << 1, end.bytes, 0, elen << 1) == 0);
#elseif python
return python.NativeStringTools.endswith(s, end);
#elseif (js && js_es >= 6)
return (cast s).endsWith(end);
#else
var elen = end.length;
var slen = s.length;
return (slen >= elen && s.indexOf(end, (slen - elen)) == (slen - elen));
#end
}
/**
Tells if the character in the string `s` at position `pos` is a space.
A character is considered to be a space character if its character code
is 9,10,11,12,13 or 32.
If `s` is the empty String `""`, or if pos is not a valid position within
`s`, the result is false.
**/
public static function isSpace(s:String, pos:Int):Bool {
#if (python || lua)
if (s.length == 0 || pos < 0 || pos >= s.length)
return false;
#end
var c = s.charCodeAt(pos);
return (c > 8 && c < 14) || c == 32;
}
/**
Removes leading space characters of `s`.
This function internally calls `isSpace()` to decide which characters to
remove.
If `s` is the empty String `""` or consists only of space characters, the
result is the empty String `""`.
**/
public #if cs inline #end static function ltrim(s:String):String {
#if cs
return untyped s.TrimStart();
#else
var l = s.length;
var r = 0;
while (r < l && isSpace(s, r)) {
r++;
}
if (r > 0)
return s.substr(r, l - r);
else
return s;
#end
}
/**
Removes trailing space characters of `s`.
This function internally calls `isSpace()` to decide which characters to
remove.
If `s` is the empty String `""` or consists only of space characters, the
result is the empty String `""`.
**/
public #if cs inline #end static function rtrim(s:String):String {
#if cs
return untyped s.TrimEnd();
#else
var l = s.length;
var r = 0;
while (r < l && isSpace(s, l - r - 1)) {
r++;
}
if (r > 0) {
return s.substr(0, l - r);
} else {
return s;
}
#end
}
/**
Removes leading and trailing space characters of `s`.
This is a convenience function for `ltrim(rtrim(s))`.
**/
public #if (cs || java) inline #end static function trim(s:String):String {
#if cs
return untyped s.Trim();
#elseif java
return (cast s : java.NativeString).trim();
#else
return ltrim(rtrim(s));
#end
}
/**
Concatenates `c` to `s` until `s.length` is at least `l`.
If `c` is the empty String `""` or if `l` does not exceed `s.length`,
`s` is returned unchanged.
If `c.length` is 1, the resulting String length is exactly `l`.
Otherwise the length may exceed `l`.
If `c` is null, the result is unspecified.
**/
public static function lpad(s:String, c:String, l:Int):String {
if (c.length <= 0)
return s;
var buf = new StringBuf();
l -= s.length;
while (buf.length < l) {
buf.add(c);
}
buf.add(s);
return buf.toString();
}
/**
Appends `c` to `s` until `s.length` is at least `l`.
If `c` is the empty String `""` or if `l` does not exceed `s.length`,
`s` is returned unchanged.
If `c.length` is 1, the resulting String length is exactly `l`.
Otherwise the length may exceed `l`.
If `c` is null, the result is unspecified.
**/
public static function rpad(s:String, c:String, l:Int):String {
if (c.length <= 0)
return s;
var buf = new StringBuf();
buf.add(s);
while (buf.length < l) {
buf.add(c);
}
return buf.toString();
}
/**
Replace all occurrences of the String `sub` in the String `s` by the
String `by`.
If `sub` is the empty String `""`, `by` is inserted after each character
of `s` except the last one. If `by` is also the empty String `""`, `s`
remains unchanged.
If `sub` or `by` are null, the result is unspecified.
**/
public static function replace(s:String, sub:String, by:String):String {
#if java
if (sub.length == 0)
return s.split(sub).join(by);
else
return (cast s : java.NativeString).replace(sub, by);
#elseif cs
if (sub.length == 0)
return s.split(sub).join(by);
else
return untyped s.Replace(sub, by);
#else
return s.split(sub).join(by);
#end
}
/**
Encodes `n` into a hexadecimal representation.
If `digits` is specified, the resulting String is padded with "0" until
its `length` equals `digits`.
**/
public static function hex(n:Int, ?digits:Int) {
#if flash
var n:UInt = n;
var s:String = untyped n.toString(16);
s = s.toUpperCase();
#else
var s = "";
var hexChars = "0123456789ABCDEF";
do {
s = hexChars.charAt(n & 15) + s;
n >>>= 4;
} while (n > 0);
#end
#if python
if (digits != null && s.length < digits) {
var diff = digits - s.length;
for (_ in 0...diff) {
s = "0" + s;
}
}
#else
if (digits != null)
while (s.length < digits)
s = "0" + s;
#end
return s;
}
/**
Returns the character code at position `index` of String `s`, or an
end-of-file indicator at if `position` equals `s.length`.
This method is faster than `String.charCodeAt()` on some platforms, but
the result is unspecified if `index` is negative or greater than
`s.length`.
End of file status can be checked by calling `StringTools.isEof()` with
the returned value as argument.
This operation is not guaranteed to work if `s` contains the `\0`
character.
**/
public static #if !eval inline #end function fastCodeAt(s:String, index:Int):Int {
#if neko
return untyped __dollar__sget(s.__s, index);
#elseif cpp
return untyped s.cca(index);
#elseif flash
return untyped s.cca(index);
#elseif java
return (index < s.length) ? cast(_charAt(s, index), Int) : -1;
#elseif cs
return (cast(index, UInt) < s.length) ? cast(s[index], Int) : -1;
#elseif js
return (cast s).charCodeAt(index);
#elseif python
return if (index >= s.length) -1 else python.internal.UBuiltins.ord(python.Syntax.arrayAccess(s, index));
#elseif hl
return @:privateAccess s.bytes.getUI16(index << 1);
#elseif lua
#if lua_vanilla
return lua.NativeStringTools.byte(s, index + 1);
#else
return lua.lib.luautf8.Utf8.byte(s, index + 1);
#end
#else
return untyped s.cca(index);
#end
}
/**
Returns the character code at position `index` of String `s`, or an
end-of-file indicator at if `position` equals `s.length`.
This method is faster than `String.charCodeAt()` on some platforms, but
the result is unspecified if `index` is negative or greater than
`s.length`.
This operation is not guaranteed to work if `s` contains the `\0`
character.
**/
public static #if !eval inline #end function unsafeCodeAt(s:String, index:Int):Int {
#if neko
return untyped __dollar__sget(s.__s, index);
#elseif cpp
return untyped s.cca(index);
#elseif flash
return untyped s.cca(index);
#elseif java
return cast(_charAt(s, index), Int);
#elseif cs
return cast(s[index], Int);
#elseif js
return (cast s).charCodeAt(index);
#elseif python
return python.internal.UBuiltins.ord(python.Syntax.arrayAccess(s, index));
#elseif hl
return @:privateAccess s.bytes.getUI16(index << 1);
#elseif lua
#if lua_vanilla
return lua.NativeStringTools.byte(s, index + 1);
#else
return lua.lib.luautf8.Utf8.byte(s, index + 1);
#end
#else
return untyped s.cca(index);
#end
}
/**
Returns an iterator of the char codes.
Note that char codes may differ across platforms because of different
internal encoding of strings in different runtimes.
For the consistent cross-platform UTF8 char codes see `haxe.iterators.StringIteratorUnicode`.
**/
public static inline function iterator(s:String):StringIterator {
return new StringIterator(s);
}
/**
Returns an iterator of the char indexes and codes.
Note that char codes may differ across platforms because of different
internal encoding of strings in different of runtimes.
For the consistent cross-platform UTF8 char codes see `haxe.iterators.StringKeyValueIteratorUnicode`.
**/
public static inline function keyValueIterator(s:String):StringKeyValueIterator {
return new StringKeyValueIterator(s);
}
/**
Tells if `c` represents the end-of-file (EOF) character.
**/
@:noUsing public static inline function isEof(c:Int):Bool {
#if (flash || cpp || hl)
return c == 0;
#elseif js
return c != c; // fast NaN
#elseif (neko || lua || eval)
return c == null;
#elseif (cs || java || python)
return c == -1;
#else
return false;
#end
}
/**
Returns a String that can be used as a single command line argument
on Unix.
The input will be quoted, or escaped if necessary.
**/
@:noCompletion
@:deprecated('StringTools.quoteUnixArg() is deprecated. Use haxe.SysTools.quoteUnixArg() instead.')
public static function quoteUnixArg(argument:String):String {
return inline haxe.SysTools.quoteUnixArg(argument);
}
/**
Character codes of the characters that will be escaped by `quoteWinArg(_, true)`.
**/
@:noCompletion
@:deprecated('StringTools.winMetaCharacters is deprecated. Use haxe.SysTools.winMetaCharacters instead.')
public static var winMetaCharacters:Array<Int> = cast haxe.SysTools.winMetaCharacters;
/**
Returns a String that can be used as a single command line argument
on Windows.
The input will be quoted, or escaped if necessary, such that the output
will be parsed as a single argument using the rule specified in
http://msdn.microsoft.com/en-us/library/ms880421
Examples:
```haxe
quoteWinArg("abc") == "abc";
quoteWinArg("ab c") == '"ab c"';
```
**/
@:noCompletion
@:deprecated('StringTools.quoteWinArg() is deprecated. Use haxe.SysTools.quoteWinArg() instead.')
public static function quoteWinArg(argument:String, escapeMetaCharacters:Bool):String {
return inline haxe.SysTools.quoteWinArg(argument, escapeMetaCharacters);
}
#if java
private static inline function _charAt(str:String, idx:Int):java.StdTypes.Char16
return (cast str : java.NativeString).charAt(idx);
#end
#if neko
private static var _urlEncode = neko.Lib.load("std", "url_encode", 1);
private static var _urlDecode = neko.Lib.load("std", "url_decode", 1);
#end
#if utf16
static inline var MIN_SURROGATE_CODE_POINT = 65536;
static inline function utf16CodePointAt(s:String, index:Int):Int {
var c = StringTools.fastCodeAt(s, index);
if (c >= 0xD800 && c <= 0xDBFF) {
c = ((c - 0xD7C0) << 10) | (StringTools.fastCodeAt(s, index + 1) & 0x3FF);
}
return c;
}
#end
}

View File

@ -0,0 +1,171 @@
/*
* 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.
*/
/**
This class provides access to various base functions of system platforms.
Look in the `sys` package for more system APIs.
**/
@:require(sys)
extern class Sys {
/**
Prints any value to the standard output.
**/
static function print(v:Dynamic):Void;
/**
Prints any value to the standard output, followed by a newline.
On Windows, this function outputs a CRLF newline.
LF newlines are printed on all other platforms.
**/
static function println(v:Dynamic):Void;
/**
Returns all the arguments that were passed in the command line.
This does not include the interpreter or the name of the program file.
(java)(eval) On Windows, non-ASCII Unicode arguments will not work correctly.
(cs) Non-ASCII Unicode arguments will not work correctly.
**/
static function args():Array<String>;
/**
Returns the value of the given environment variable, or `null` if it
doesn't exist.
**/
static function getEnv(s:String):String;
/**
Sets the value of the given environment variable.
(java) This functionality is not available on Java; calling this function will throw.
**/
static function putEnv(s:String, v:String):Void;
/**
Returns all environment variables.
**/
static function environment():Map<String, String>;
/**
Suspends execution for the given length of time (in seconds).
**/
static function sleep(seconds:Float):Void;
/**
Changes the current time locale, which will affect `DateTools.format` date formating.
Returns `true` if the locale was successfully changed.
**/
static function setTimeLocale(loc:String):Bool;
/**
Gets the current working directory (usually the one in which the program was started).
**/
static function getCwd():String;
/**
Changes the current working directory.
(java) This functionality is not available on Java; calling this function will throw.
**/
static function setCwd(s:String):Void;
/**
Returns the type of the current system. Possible values are:
- `"Windows"`
- `"Linux"`
- `"BSD"`
- `"Mac"`
**/
static function systemName():String;
/**
Runs the given command. The command output will be printed to the same output as the current process.
The current process will block until the command terminates.
The return value is the exit code of the command (usually `0` indicates no error).
Command arguments can be passed in two ways:
1. Using `args` to pass command arguments. Each argument will be automatically quoted and shell meta-characters will be escaped if needed.
`cmd` should be an executable name that can be located in the `PATH` environment variable, or a full path to an executable.
2. When `args` is not given or is `null`, command arguments can be appended to `cmd`. No automatic quoting/escaping will be performed. `cmd` should be formatted exactly as it would be when typed at the command line.
It can run executables, as well as shell commands that are not executables (e.g. on Windows: `dir`, `cd`, `echo` etc).
Use the `sys.io.Process` API for more complex tasks, such as background processes, or providing input to the command.
**/
static function command(cmd:String, ?args:Array<String>):Int;
/**
Exits the current process with the given exit code.
(macro)(eval) Being invoked in a macro or eval context (e.g. with `-x` or `--run`) immediately terminates
the compilation process, which also prevents the execution of any `--next` sections of compilation arguments.
**/
static function exit(code:Int):Void;
/**
Gives the most precise timestamp value available (in seconds).
**/
static function time():Float;
/**
Gives the most precise timestamp value available (in seconds),
but only accounts for the actual time spent running on the CPU for the current thread/process.
**/
static function cpuTime():Float;
/**
Returns the path to the current executable that we are running.
**/
@:deprecated("Use programPath instead") static function executablePath():String;
/**
Returns the absolute path to the current program file that we are running.
Concretely, for an executable binary, it returns the path to the binary.
For a script (e.g. a PHP file), it returns the path to the script.
**/
static function programPath():String;
/**
Reads a single input character from the standard input and returns it.
Setting `echo` to `true` will also display the character on the output.
**/
static function getChar(echo:Bool):Int;
/**
Returns the standard input of the process, from which user input can be read.
Usually it will block until the user sends a full input line.
See `getChar` for an alternative.
**/
static function stdin():haxe.io.Input;
/**
Returns the standard output of the process, to which program output can be written.
**/
static function stdout():haxe.io.Output;
/**
Returns the standard error of the process, to which program errors can be written.
**/
static function stderr():haxe.io.Output;
}

View File

@ -0,0 +1,295 @@
/*
* 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.
*/
/**
The Haxe Reflection API allows retrieval of type information at runtime.
This class complements the more lightweight Reflect class, with a focus on
class and enum instances.
@see https://haxe.org/manual/types.html
@see https://haxe.org/manual/std-reflection.html
**/
extern class Type {
/**
Returns the class of `o`, if `o` is a class instance.
If `o` is null or of a different type, null is returned.
In general, type parameter information cannot be obtained at runtime.
**/
static function getClass<T>(o:T):Class<T>;
/**
Returns the enum of enum instance `o`.
An enum instance is the result of using an enum constructor. Given an
`enum Color { Red; }`, `getEnum(Red)` returns `Enum<Color>`.
If `o` is null, null is returned.
In general, type parameter information cannot be obtained at runtime.
**/
static function getEnum(o:EnumValue):Enum<Dynamic>;
/**
Returns the super-class of class `c`.
If `c` has no super class, null is returned.
If `c` is null, the result is unspecified.
In general, type parameter information cannot be obtained at runtime.
**/
static function getSuperClass(c:Class<Dynamic>):Class<Dynamic>;
/**
Returns the name of class `c`, including its path.
If `c` is inside a package, the package structure is returned dot-
separated, with another dot separating the class name:
`pack1.pack2.(...).packN.ClassName`
If `c` is a sub-type of a Haxe module, that module is not part of the
package structure.
If `c` has no package, the class name is returned.
If `c` is null, the result is unspecified.
The class name does not include any type parameters.
**/
static function getClassName(c:Class<Dynamic>):String;
/**
Returns the name of enum `e`, including its path.
If `e` is inside a package, the package structure is returned dot-
separated, with another dot separating the enum name:
`pack1.pack2.(...).packN.EnumName`
If `e` is a sub-type of a Haxe module, that module is not part of the
package structure.
If `e` has no package, the enum name is returned.
If `e` is null, the result is unspecified.
The enum name does not include any type parameters.
**/
static function getEnumName(e:Enum<Dynamic>):String;
/**
Resolves a class by name.
If `name` is the path of an existing class, that class is returned.
Otherwise null is returned.
If `name` is null or the path to a different type, the result is
unspecified.
The class name must not include any type parameters.
**/
static function resolveClass(name:String):Class<Dynamic>;
/**
Resolves an enum by name.
If `name` is the path of an existing enum, that enum is returned.
Otherwise null is returned.
If `name` is null the result is unspecified.
If `name` is the path to a different type, null is returned.
The enum name must not include any type parameters.
**/
static function resolveEnum(name:String):Enum<Dynamic>;
/**
Creates an instance of class `cl`, using `args` as arguments to the
class constructor.
This function guarantees that the class constructor is called.
Default values of constructors arguments are not guaranteed to be
taken into account.
If `cl` or `args` are null, or if the number of elements in `args` does
not match the expected number of constructor arguments, or if any
argument has an invalid type, or if `cl` has no own constructor, the
result is unspecified.
In particular, default values of constructor arguments are not
guaranteed to be taken into account.
**/
static function createInstance<T>(cl:Class<T>, args:Array<Dynamic>):T;
/**
Creates an instance of class `cl`.
This function guarantees that the class constructor is not called.
If `cl` is null, the result is unspecified.
**/
static function createEmptyInstance<T>(cl:Class<T>):T;
/**
Creates an instance of enum `e` by calling its constructor `constr` with
arguments `params`.
If `e` or `constr` is null, or if enum `e` has no constructor named
`constr`, or if the number of elements in `params` does not match the
expected number of constructor arguments, or if any argument has an
invalid type, the result is unspecified.
**/
static function createEnum<T>(e:Enum<T>, constr:String, ?params:Array<Dynamic>):T;
/**
Creates an instance of enum `e` by calling its constructor number
`index` with arguments `params`.
The constructor indices are preserved from Haxe syntax, so the first
declared is index 0, the next index 1 etc.
If `e` or `constr` is null, or if enum `e` has no constructor named
`constr`, or if the number of elements in `params` does not match the
expected number of constructor arguments, or if any argument has an
invalid type, the result is unspecified.
**/
static function createEnumIndex<T>(e:Enum<T>, index:Int, ?params:Array<Dynamic>):T;
/**
Returns a list of the instance fields of class `c`, including
inherited fields.
This only includes fields which are known at compile-time. In
particular, using `getInstanceFields(getClass(obj))` will not include
any fields which were added to `obj` at runtime.
The order of the fields in the returned Array is unspecified.
If `c` is null, the result is unspecified.
**/
static function getInstanceFields(c:Class<Dynamic>):Array<String>;
/**
Returns a list of static fields of class `c`.
This does not include static fields of parent classes.
The order of the fields in the returned Array is unspecified.
If `c` is null, the result is unspecified.
**/
static function getClassFields(c:Class<Dynamic>):Array<String>;
/**
Returns a list of the names of all constructors of enum `e`.
The order of the constructor names in the returned Array is preserved
from the original syntax.
If `e` is null, the result is unspecified.
**/
static function getEnumConstructs(e:Enum<Dynamic>):Array<String>;
/**
Returns the runtime type of value `v`.
The result corresponds to the type `v` has at runtime, which may vary
per platform. Assumptions regarding this should be minimized to avoid
surprises.
**/
static function typeof(v:Dynamic):ValueType;
/**
Recursively compares two enum instances `a` and `b` by value.
Unlike `a == b`, this function performs a deep equality check on the
arguments of the constructors, if exists.
If `a` or `b` are null, the result is unspecified.
**/
static function enumEq<T:EnumValue>(a:T, b:T):Bool;
/**
Returns the constructor name of enum instance `e`.
The result String does not contain any constructor arguments.
If `e` is null, the result is unspecified.
**/
static function enumConstructor(e:EnumValue):String;
/**
Returns a list of the constructor arguments of enum instance `e`.
If `e` has no arguments, the result is [].
Otherwise the result are the values that were used as arguments to `e`,
in the order of their declaration.
If `e` is null, the result is unspecified.
**/
static function enumParameters(e:EnumValue):Array<Dynamic>;
/**
Returns the index of enum instance `e`.
This corresponds to the original syntactic position of `e`. The index of
the first declared constructor is 0, the next one is 1 etc.
If `e` is null, the result is unspecified.
**/
static function enumIndex(e:EnumValue):Int;
/**
Returns a list of all constructors of enum `e` that require no
arguments.
This may return the empty Array `[]` if all constructors of `e` require
arguments.
Otherwise an instance of `e` constructed through each of its non-
argument constructors is returned, in the order of the constructor
declaration.
If `e` is null, the result is unspecified.
**/
static function allEnums<T>(e:Enum<T>):Array<T>;
}
/**
The different possible runtime types of a value.
**/
enum ValueType {
TNull;
TInt;
TFloat;
TBool;
TObject;
TFunction;
TClass(c:Class<Dynamic>);
TEnum(e:Enum<Dynamic>);
TUnknown;
}

View File

@ -0,0 +1,321 @@
/*
* 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.
*/
#if ((flash || flash9doc || cs || hl) && !doc_gen)
/**
The unsigned `Int` type is only defined for Flash and C#. It's currently
handled the same as a normal Int.
@see https://haxe.org/manual/types-basic-types.html
**/
@:coreType
@:notNull
@:runtimeValue
@:analyzer(no_const_propagation)
abstract UInt to Int from Int {
@:commutative @:op(A + B) private static function addI(lhs:UInt, rhs:Int):UInt;
@:commutative @:op(A + B) private static function addF(lhs:UInt, rhs:Float):Float;
@:op(A + B) private static function add(lhs:UInt, rhs:UInt):UInt;
@:commutative @:op(A * B) private static function mulI(lhs:UInt, rhs:Int):UInt;
@:commutative @:op(A * B) private static function mulF(lhs:UInt, rhs:Float):Float;
@:op(A * B) private static function mul(lhs:UInt, rhs:UInt):UInt;
@:op(A % B) private static function modI(lhs:UInt, rhs:Int):UInt;
@:op(A % B) private static function modF(lhs:UInt, rhs:Float):Float;
@:op(A % B) private static function mod(lhs:UInt, rhs:UInt):UInt;
@:op(A - B) private static function subI(lhs:UInt, rhs:Int):UInt;
@:op(A - B) private static function subF(lhs:UInt, rhs:Float):Float;
@:op(A - B) private static function sub(lhs:UInt, rhs:UInt):UInt;
@:op(A / B) private static function divI(lhs:UInt, rhs:Int):Float;
@:op(A / B) private static function divF(lhs:UInt, rhs:Float):Float;
@:op(A / B) private static function div(lhs:UInt, rhs:UInt):Float;
@:commutative @:op(A | B) private static function orI(lhs:UInt, rhs:Int):UInt;
@:op(A | B) private static function or(lhs:UInt, rhs:UInt):UInt;
@:commutative @:op(A ^ B) private static function xorI(lhs:UInt, rhs:Int):UInt;
@:op(A ^ B) private static function xor(lhs:UInt, rhs:UInt):UInt;
@:commutative @:op(A & B) private static function andI(lhs:UInt, rhs:Int):UInt;
@:op(A & B) private static function and(lhs:UInt, rhs:UInt):UInt;
@:op(A << B) private static function shl(lhs:UInt, rhs:Int):UInt;
@:op(A >> B) private static inline function shr(lhs:UInt, rhs:Int):UInt
return lhs >>> rhs;
@:op(A >>> B) private static function ushr(lhs:UInt, rhs:Int):UInt;
@:op(A > B) private static function gt(lhs:UInt, rhs:UInt):Bool;
@:op(A >= B) private static function gte(lhs:UInt, rhs:UInt):Bool;
@:op(A < B) private static function lt(lhs:UInt, rhs:UInt):Bool;
@:op(A <= B) private static function lte(lhs:UInt, rhs:UInt):Bool;
@:op(A > B) private static function gtf(lhs:UInt, rhs:Float):Bool;
@:op(A > B) private static function gtf2(lhs:Float, rhs:UInt):Bool;
@:op(A >= B) private static function gtef(lhs:UInt, rhs:Float):Bool;
@:op(A >= B) private static function gtef2(lhs:Float, rhs:UInt):Bool;
@:op(A < B) private static function ltf(lhs:UInt, rhs:Float):Bool;
@:op(A < B) private static function ltf2(lhs:Float, rhs:UInt):Bool;
@:op(A <= B) private static function ltef(lhs:UInt, rhs:Float):Bool;
@:op(A <= B) private static function ltef2(lhs:Float, rhs:UInt):Bool;
@:op(~A) private static function bneg(t:UInt):UInt;
@:commutative @:op(A == B) private static function equalsInt<T:Int>(a:UInt, b:T):Bool;
@:commutative @:op(A != B) private static function notEqualsInt<T:Int>(a:UInt, b:T):Bool;
@:commutative @:op(A == B) private static function equalsFloat<T:Float>(a:UInt, b:T):Bool;
@:commutative @:op(A != B) private static function notEqualsFloat<T:Float>(a:UInt, b:T):Bool;
@:op(++A) private function prefixIncrement():UInt;
@:op(A++) private function postfixIncrement():UInt;
@:op(--A) private function prefixDecrement():UInt;
@:op(A--) private function postfixDecrement():UInt;
}
#else
/**
The unsigned `Int` type is only defined for Flash and C#.
Simulate it for other platforms.
@see https://haxe.org/manual/types-basic-types.html
**/
@:transitive
abstract UInt(Int) from Int to Int {
@:op(A + B) private static inline function add(a:UInt, b:UInt):UInt {
return a.toInt() + b.toInt();
}
@:op(A / B) private static inline function div(a:UInt, b:UInt):Float {
return a.toFloat() / b.toFloat();
}
@:op(A * B) private static inline function mul(a:UInt, b:UInt):UInt {
return a.toInt() * b.toInt();
}
@:op(A - B) private static inline function sub(a:UInt, b:UInt):UInt {
return a.toInt() - b.toInt();
}
@:op(A > B)
private static #if !js inline #end function gt(a:UInt, b:UInt):Bool {
var aNeg = a.toInt() < 0;
var bNeg = b.toInt() < 0;
return if (aNeg != bNeg) aNeg; else a.toInt() > b.toInt();
}
@:op(A >= B)
private static #if !js inline #end function gte(a:UInt, b:UInt):Bool {
var aNeg = a.toInt() < 0;
var bNeg = b.toInt() < 0;
return if (aNeg != bNeg) aNeg; else a.toInt() >= b.toInt();
}
@:op(A < B) private static inline function lt(a:UInt, b:UInt):Bool {
return gt(b, a);
}
@:op(A <= B) private static inline function lte(a:UInt, b:UInt):Bool {
return gte(b, a);
}
@:op(A & B) private static inline function and(a:UInt, b:UInt):UInt {
return a.toInt() & b.toInt();
}
@:op(A | B) private static inline function or(a:UInt, b:UInt):UInt {
return a.toInt() | b.toInt();
}
@:op(A ^ B) private static inline function xor(a:UInt, b:UInt):UInt {
return a.toInt() ^ b.toInt();
}
@:op(A << B) private static inline function shl(a:UInt, b:Int):UInt {
return a.toInt() << b;
}
@:op(A >> B) private static inline function shr(a:UInt, b:Int):UInt {
return a.toInt() >>> b;
}
@:op(A >>> B) private static inline function ushr(a:UInt, b:Int):UInt {
return a.toInt() >>> b;
}
@:op(A % B) private static inline function mod(a:UInt, b:UInt):UInt {
return Std.int(a.toFloat() % b.toFloat());
}
@:commutative @:op(A + B) private static inline function addWithFloat(a:UInt, b:Float):Float {
return a.toFloat() + b;
}
@:commutative @:op(A * B) private static inline function mulWithFloat(a:UInt, b:Float):Float {
return a.toFloat() * b;
}
@:op(A / B) private static inline function divFloat(a:UInt, b:Float):Float {
return a.toFloat() / b;
}
@:op(A / B) private static inline function floatDiv(a:Float, b:UInt):Float {
return a / b.toFloat();
}
@:op(A - B) private static inline function subFloat(a:UInt, b:Float):Float {
return a.toFloat() - b;
}
@:op(A - B) private static inline function floatSub(a:Float, b:UInt):Float {
return a - b.toFloat();
}
@:op(A > B) private static inline function gtFloat(a:UInt, b:Float):Bool {
return a.toFloat() > b;
}
@:commutative @:op(A == B) private static inline function equalsInt<T:Int>(a:UInt, b:T):Bool {
return a.toInt() == b;
}
@:commutative @:op(A != B) private static inline function notEqualsInt<T:Int>(a:UInt, b:T):Bool {
return a.toInt() != b;
}
@:commutative @:op(A == B) private static inline function equalsFloat<T:Float>(a:UInt, b:T):Bool {
return a.toFloat() == b;
}
@:commutative @:op(A != B) private static inline function notEqualsFloat<T:Float>(a:UInt, b:T):Bool {
return a.toFloat() != b;
}
@:op(A >= B) private static inline function gteFloat(a:UInt, b:Float):Bool {
return a.toFloat() >= b;
}
@:op(A > B) private static inline function floatGt(a:Float, b:UInt):Bool {
return a > b.toFloat();
}
@:op(A >= B) private static inline function floatGte(a:Float, b:UInt):Bool {
return a >= b.toFloat();
}
@:op(A < B) private static inline function ltFloat(a:UInt, b:Float):Bool {
return a.toFloat() < b;
}
@:op(A <= B) private static inline function lteFloat(a:UInt, b:Float):Bool {
return a.toFloat() <= b;
}
@:op(A < B) private static inline function floatLt(a:Float, b:UInt):Bool {
return a < b.toFloat();
}
@:op(A <= B) private static inline function floatLte(a:Float, b:UInt):Bool {
return a <= b.toFloat();
}
@:op(A % B) private static inline function modFloat(a:UInt, b:Float):Float {
return a.toFloat() % b;
}
@:op(A % B) private static inline function floatMod(a:Float, b:UInt):Float {
return a % b.toFloat();
}
@:op(~A) private inline function negBits():UInt {
return ~this;
}
@:op(++A) private inline function prefixIncrement():UInt {
return ++this;
}
@:op(A++) private inline function postfixIncrement():UInt {
return this++;
}
@:op(--A) private inline function prefixDecrement():UInt {
return --this;
}
@:op(A--) private inline function postfixDecrement():UInt {
return this--;
}
// TODO: radix is just defined to deal with doc_gen issues
private inline function toString(?radix:Int):String {
return Std.string(toFloat());
}
private inline function toInt():Int {
return this;
}
@:to private #if (!js || analyzer) inline #end function toFloat():Float {
var int = toInt();
if (int < 0) {
return 4294967296.0 + int;
} else {
// + 0.0 here to make sure we promote to Float on some platforms
// In particular, PHP was having issues when comparing to Int in the == op.
return int + 0.0;
}
}
}
#end

View File

@ -0,0 +1,443 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
import haxe.io.Bytes;
import haxe.io.Encoding;
import haxe.iterators.StringIteratorUnicode;
import haxe.iterators.StringKeyValueIteratorUnicode;
/**
This abstract provides consistent cross-target unicode support.
@see https://haxe.org/manual/std-UnicodeString.html
**/
@:forward
@:access(StringTools)
abstract UnicodeString(String) from String to String {
/**
Tells if `b` is a correctly encoded UTF8 byte sequence.
**/
static public function validate(b:Bytes, encoding:Encoding):Bool {
switch (encoding) {
case RawNative:
throw "UnicodeString.validate: RawNative encoding is not supported";
case UTF8:
var data = b.getData();
var pos = 0;
var max = b.length;
while (pos < max) {
var c:Int = Bytes.fastGet(data, pos++);
if (c < 0x80) {} else if (c < 0xC2) {
return false;
} else if (c < 0xE0) {
if (pos + 1 > max) {
return false;
}
var c2:Int = Bytes.fastGet(data, pos++);
if (c2 < 0x80 || c2 > 0xBF) {
return false;
}
} else if (c < 0xF0) {
if (pos + 2 > max) {
return false;
}
var c2:Int = Bytes.fastGet(data, pos++);
if (c == 0xE0) {
if (c2 < 0xA0 || c2 > 0xBF)
return false;
} else {
if (c2 < 0x80 || c2 > 0xBF)
return false;
}
var c3:Int = Bytes.fastGet(data, pos++);
if (c3 < 0x80 || c3 > 0xBF) {
return false;
}
c = (c << 16) | (c2 << 8) | c3;
if (0xEDA080 <= c && c <= 0xEDBFBF) { // surrogate pairs
return false;
}
} else if (c > 0xF4) {
return false;
} else {
if (pos + 3 > max) {
return false;
}
var c2:Int = Bytes.fastGet(data, pos++);
if (c == 0xF0) {
if (c2 < 0x90 || c2 > 0xBF)
return false;
} else if (c == 0xF4) {
if (c2 < 0x80 || c2 > 0x8F)
return false;
} else {
if (c2 < 0x80 || c2 > 0xBF)
return false;
}
var c3:Int = Bytes.fastGet(data, pos++);
if (c3 < 0x80 || c3 > 0xBF) {
return false;
}
var c4:Int = Bytes.fastGet(data, pos++);
if (c4 < 0x80 || c4 > 0xBF) {
return false;
}
}
}
return true;
}
}
#if target.unicode
/**
Creates an instance of UnicodeString.
**/
public inline function new(string:String):Void {
this = string;
}
/**
Returns an iterator of the unicode code points.
**/
public inline function iterator():StringIteratorUnicode {
return new StringIteratorUnicode(this);
}
/**
Returns an iterator of the code point indices and unicode code points.
**/
public inline function keyValueIterator():StringKeyValueIteratorUnicode {
return new StringKeyValueIteratorUnicode(this);
}
#if target.utf16
/**
The number of characters in `this` String.
**/
public var length(get, never):Int;
/**
Returns the character at position `index` of `this` String.
If `index` is negative or exceeds `this.length`, the empty String `""`
is returned.
**/
public function charAt(index:Int):String {
if (index < 0)
return '';
var unicodeOffset = 0;
var nativeOffset = 0;
while (nativeOffset < this.length) {
var c = StringTools.utf16CodePointAt(this, nativeOffset++);
if (unicodeOffset == index) {
return String.fromCharCode(c);
}
if (c >= StringTools.MIN_SURROGATE_CODE_POINT) {
nativeOffset++;
}
unicodeOffset++;
}
return '';
}
/**
Returns the character code at position `index` of `this` String.
If `index` is negative or exceeds `this.length`, `null` is returned.
**/
public function charCodeAt(index:Int):Null<Int> {
if (index < 0)
return null;
var unicodeOffset = 0;
var nativeOffset = 0;
while (nativeOffset < this.length) {
var c = StringTools.utf16CodePointAt(this, nativeOffset++);
if (unicodeOffset == index) {
return c;
}
if (c >= StringTools.MIN_SURROGATE_CODE_POINT) {
nativeOffset++;
}
unicodeOffset++;
}
return null;
}
/**
Returns the position of the leftmost occurrence of `str` within `this`
String.
If `startIndex` is given, the search is performed within the substring
of `this` String starting from `startIndex` (if `startIndex` is posivite
or 0) or `max(this.length + startIndex, 0)` (if `startIndex` is negative).
If `startIndex` exceeds `this.length`, -1 is returned.
Otherwise the search is performed within `this` String. In either case,
the returned position is relative to the beginning of `this` String.
If `str` cannot be found, -1 is returned.
**/
public function indexOf(str:String, ?startIndex:Int):Int {
if (startIndex == null) {
startIndex = 0;
} else {
if (startIndex < 0) {
startIndex = (this : UnicodeString).length + startIndex;
}
}
var unicodeOffset = 0;
var nativeOffset = 0;
var matchingOffset = 0;
var result = -1;
while (nativeOffset <= this.length) {
var c = StringTools.utf16CodePointAt(this, nativeOffset);
if (unicodeOffset >= startIndex) {
var c2 = StringTools.utf16CodePointAt(str, matchingOffset);
if (c == c2) {
if (matchingOffset == 0) {
result = unicodeOffset;
}
matchingOffset++;
if (c2 >= StringTools.MIN_SURROGATE_CODE_POINT) {
matchingOffset++;
}
if (matchingOffset == str.length) {
return result;
}
} else if (matchingOffset != 0) {
result = -1;
matchingOffset = 0;
continue;
}
}
nativeOffset++;
if (c >= StringTools.MIN_SURROGATE_CODE_POINT) {
nativeOffset++;
}
unicodeOffset++;
}
return -1;
}
/**
Returns the position of the rightmost occurrence of `str` within `this`
String.
If `startIndex` is given, the search is performed within the substring
of `this` String from 0 to `startIndex + str.length`. Otherwise the search
is performed within `this` String. In either case, the returned position
is relative to the beginning of `this` String.
If `str` cannot be found, -1 is returned.
**/
public function lastIndexOf(str:String, ?startIndex:Int):Int {
if (startIndex == null) {
startIndex = this.length;
} else if (startIndex < 0) {
startIndex = 0;
}
var unicodeOffset = 0;
var nativeOffset = 0;
var result = -1;
var lastIndex = -1;
var matchingOffset = 0;
var strUnicodeLength = (str : UnicodeString).length;
while (nativeOffset < this.length && unicodeOffset < startIndex + strUnicodeLength) {
var c = StringTools.utf16CodePointAt(this, nativeOffset);
var c2 = StringTools.utf16CodePointAt(str, matchingOffset);
if (c == c2) {
if (matchingOffset == 0) {
lastIndex = unicodeOffset;
}
matchingOffset++;
if (c2 >= StringTools.MIN_SURROGATE_CODE_POINT) {
matchingOffset++;
}
if (matchingOffset == str.length) {
result = lastIndex;
lastIndex = -1;
}
} else if (matchingOffset != 0) {
lastIndex = -1;
matchingOffset = 0;
continue;
}
nativeOffset++;
if (c >= StringTools.MIN_SURROGATE_CODE_POINT) {
nativeOffset++;
}
unicodeOffset++;
}
return result;
}
/**
Returns `len` characters of `this` String, starting at position `pos`.
If `len` is omitted, all characters from position `pos` to the end of
`this` String are included.
If `pos` is negative, its value is calculated from the end of `this`
String by `this.length + pos`. If this yields a negative value, 0 is
used instead.
If the calculated position + `len` exceeds `this.length`, the characters
from that position to the end of `this` String are returned.
If `len` is negative, the result is unspecified.
**/
public function substr(pos:Int, ?len:Int):String {
if (pos < 0) {
pos = (this : UnicodeString).length + pos;
if (pos < 0) {
pos = 0;
}
}
if (len != null) {
if (len < 0) {
len = (this : UnicodeString).length + len;
}
if (len <= 0) {
return "";
}
}
var unicodeOffset = 0;
var nativeOffset = 0;
var fromOffset = -1;
var subLength = 0;
while (nativeOffset < this.length) {
var c = StringTools.utf16CodePointAt(this, nativeOffset);
if (unicodeOffset >= pos) {
if (fromOffset < 0) {
if (len == null) {
return this.substr(nativeOffset);
}
fromOffset = nativeOffset;
}
subLength++;
if (subLength >= len) {
var lastOffset = (c < StringTools.MIN_SURROGATE_CODE_POINT ? nativeOffset : nativeOffset + 1);
return this.substr(fromOffset, lastOffset - fromOffset + 1);
}
}
nativeOffset += (c >= StringTools.MIN_SURROGATE_CODE_POINT ? 2 : 1);
unicodeOffset++;
}
return (fromOffset < 0 ? "" : this.substr(fromOffset));
}
/**
Returns the part of `this` String from `startIndex` to but not including `endIndex`.
If `startIndex` or `endIndex` are negative, 0 is used instead.
If `startIndex` exceeds `endIndex`, they are swapped.
If the (possibly swapped) `endIndex` is omitted or exceeds
`this.length`, `this.length` is used instead.
If the (possibly swapped) `startIndex` exceeds `this.length`, the empty
String `""` is returned.
**/
public function substring(startIndex:Int, ?endIndex:Int):String {
if (startIndex < 0) {
startIndex = 0;
}
if (endIndex != null) {
if (endIndex < 0) {
endIndex = 0;
}
if (startIndex == endIndex) {
return "";
}
if (startIndex > endIndex) {
var tmp = startIndex;
startIndex = endIndex;
endIndex = tmp;
}
}
var unicodeOffset = 0;
var nativeOffset = 0;
var fromOffset = -1;
var subLength = 0;
while (nativeOffset < this.length) {
var c = StringTools.utf16CodePointAt(this, nativeOffset);
if (startIndex <= unicodeOffset) {
if (fromOffset < 0) {
if (endIndex == null) {
return this.substr(nativeOffset);
}
fromOffset = nativeOffset;
}
subLength++;
if (subLength >= endIndex - startIndex) {
var lastOffset = (c < StringTools.MIN_SURROGATE_CODE_POINT ? nativeOffset : nativeOffset + 1);
return this.substr(fromOffset, lastOffset - fromOffset + 1);
}
}
nativeOffset += (c >= StringTools.MIN_SURROGATE_CODE_POINT ? 2 : 1);
unicodeOffset++;
}
return (fromOffset < 0 ? "" : this.substr(fromOffset));
}
function get_length():Int {
var l = 0;
for (c in new StringIteratorUnicode(this)) {
l++;
}
return l;
}
#end
#end
@:op(A < B) static function lt(a:UnicodeString, b:UnicodeString):Bool;
@:op(A <= B) static function lte(a:UnicodeString, b:UnicodeString):Bool;
@:op(A > B) static function gt(a:UnicodeString, b:UnicodeString):Bool;
@:op(A >= B) static function gte(a:UnicodeString, b:UnicodeString):Bool;
@:op(A == B) static function eq(a:UnicodeString, b:UnicodeString):Bool;
@:op(A != B) static function neq(a:UnicodeString, b:UnicodeString):Bool;
@:op(A + B) static function add(a:UnicodeString, b:UnicodeString):UnicodeString;
@:op(A += B) static function assignAdd(a:UnicodeString, b:UnicodeString):UnicodeString;
@:op(A + B) @:commutative static function add(a:UnicodeString, b:String):UnicodeString;
@:op(A += B) @:commutative static function assignAdd(a:UnicodeString, b:String):UnicodeString;
}

View File

@ -0,0 +1,408 @@
/*
* 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.
*/
/**
Xml node types.
@see https://haxe.org/manual/std-Xml.html
**/
enum abstract XmlType(Int) {
/**
Represents an XML element type.
**/
var Element = 0;
/**
Represents XML parsed character data type.
**/
var PCData = 1;
/**
Represents XML character data type.
**/
var CData = 2;
/**
Represents an XML comment type.
**/
var Comment = 3;
/**
Represents an XML doctype element type.
**/
var DocType = 4;
/**
Represents an XML processing instruction type.
**/
var ProcessingInstruction = 5;
/**
Represents an XML document type.
**/
var Document = 6;
public function toString():String {
return switch (cast this : XmlType) {
case Element: "Element";
case PCData: "PCData";
case CData: "CData";
case Comment: "Comment";
case DocType: "DocType";
case ProcessingInstruction: "ProcessingInstruction";
case Document: "Document";
};
}
}
/**
Cross-platform Xml API.
@see https://haxe.org/manual/std-Xml.html
**/
class Xml {
/**
XML element type.
**/
static public var Element(default, never) = XmlType.Element;
/**
XML parsed character data type.
**/
static public var PCData(default, never) = XmlType.PCData;
/**
XML character data type.
**/
static public var CData(default, never) = XmlType.CData;
/**
XML comment type.
**/
static public var Comment(default, never) = XmlType.Comment;
/**
XML doctype element type.
**/
static public var DocType(default, never) = XmlType.DocType;
/**
XML processing instruction type.
**/
static public var ProcessingInstruction(default, never) = XmlType.ProcessingInstruction;
/**
XML document type.
**/
static public var Document(default, never) = XmlType.Document;
/**
Parses the String into an Xml document.
**/
static public function parse(str:String):Xml {
return haxe.xml.Parser.parse(str);
}
/**
Returns the type of the Xml Node. This should be used before
accessing other functions since some might raise an exception
if the node type is not correct.
**/
public var nodeType(default, null):XmlType;
/**
Returns the node name of an Element.
**/
@:isVar public var nodeName(get, set):String;
/**
Returns the node value. Only works if the Xml node is not an Element or a Document.
**/
@:isVar public var nodeValue(get, set):String;
/**
Returns the parent object in the Xml hierarchy.
The parent can be `null`, an Element or a Document.
**/
public var parent(default, null):Xml;
var children:Array<Xml>;
var attributeMap:Map<String, String>;
#if !cppia inline #end function get_nodeName() {
if (nodeType != Element) {
throw 'Bad node type, expected Element but found $nodeType';
}
return nodeName;
}
#if !cppia inline #end function set_nodeName(v) {
if (nodeType != Element) {
throw 'Bad node type, expected Element but found $nodeType';
}
return this.nodeName = v;
}
#if !cppia inline #end function get_nodeValue() {
if (nodeType == Document || nodeType == Element) {
throw 'Bad node type, unexpected $nodeType';
}
return nodeValue;
}
#if !cppia inline #end function set_nodeValue(v) {
if (nodeType == Document || nodeType == Element) {
throw 'Bad node type, unexpected $nodeType';
}
return this.nodeValue = v;
}
/**
Creates a node of the given type.
**/
static public function createElement(name:String):Xml {
var xml = new Xml(Element);
xml.nodeName = name;
return xml;
}
/**
Creates a node of the given type.
**/
static public function createPCData(data:String):Xml {
var xml = new Xml(PCData);
xml.nodeValue = data;
return xml;
}
/**
Creates a node of the given type.
**/
static public function createCData(data:String):Xml {
var xml = new Xml(CData);
xml.nodeValue = data;
return xml;
}
/**
Creates a node of the given type.
**/
static public function createComment(data:String):Xml {
var xml = new Xml(Comment);
xml.nodeValue = data;
return xml;
}
/**
Creates a node of the given type.
**/
static public function createDocType(data:String):Xml {
var xml = new Xml(DocType);
xml.nodeValue = data;
return xml;
}
/**
Creates a node of the given type.
**/
static public function createProcessingInstruction(data:String):Xml {
var xml = new Xml(ProcessingInstruction);
xml.nodeValue = data;
return xml;
}
/**
Creates a node of the given type.
**/
static public function createDocument():Xml {
return new Xml(Document);
}
/**
Get the given attribute of an Element node. Returns `null` if not found.
Attributes are case-sensitive.
**/
public function get(att:String):String {
if (nodeType != Element) {
throw 'Bad node type, expected Element but found $nodeType';
}
return attributeMap[att];
}
/**
Set the given attribute value for an Element node.
Attributes are case-sensitive.
**/
public function set(att:String, value:String):Void {
if (nodeType != Element) {
throw 'Bad node type, expected Element but found $nodeType';
}
attributeMap.set(att, value);
}
/**
Removes an attribute for an Element node.
Attributes are case-sensitive.
**/
public function remove(att:String):Void {
if (nodeType != Element) {
throw 'Bad node type, expected Element but found $nodeType';
}
attributeMap.remove(att);
}
/**
Tells if the Element node has a given attribute.
Attributes are case-sensitive.
**/
public function exists(att:String):Bool {
if (nodeType != Element) {
throw 'Bad node type, expected Element but found $nodeType';
}
return attributeMap.exists(att);
}
/**
Returns an `Iterator` on all the attribute names.
**/
public function attributes():Iterator<String> {
if (nodeType != Element) {
throw 'Bad node type, expected Element but found $nodeType';
}
return attributeMap.keys();
}
/**
Returns an iterator of all child nodes.
Only works if the current node is an Element or a Document.
**/
public #if !cppia inline #end function iterator():Iterator<Xml> {
ensureElementType();
return children.iterator();
}
/**
Returns an iterator of all child nodes which are Elements.
Only works if the current node is an Element or a Document.
**/
public function elements():Iterator<Xml> {
ensureElementType();
var ret = [for (child in children) if (child.nodeType == Element) child];
return ret.iterator();
}
/**
Returns an iterator of all child nodes which are Elements with the given nodeName.
Only works if the current node is an Element or a Document.
**/
public function elementsNamed(name:String):Iterator<Xml> {
ensureElementType();
var ret = [
for (child in children)
if (child.nodeType == Element && child.nodeName == name) child
];
return ret.iterator();
}
/**
Returns the first child node.
**/
public #if !cppia inline #end function firstChild():Xml {
ensureElementType();
return children[0];
}
/**
Returns the first child node which is an Element.
**/
public function firstElement():Xml {
ensureElementType();
for (child in children) {
if (child.nodeType == Element) {
return child;
}
}
return null;
}
/**
Adds a child node to the Document or Element.
A child node can only be inside one given parent node, which is indicated by the `parent` property.
If the child is already inside this Document or Element, it will be moved to the last position among the Document or Element's children.
If the child node was previously inside a different node, it will be moved to this Document or Element.
**/
public function addChild(x:Xml):Void {
ensureElementType();
if (x.parent != null) {
x.parent.removeChild(x);
}
children.push(x);
x.parent = this;
}
/**
Removes a child from the Document or Element.
Returns true if the child was successfuly removed.
**/
public function removeChild(x:Xml):Bool {
ensureElementType();
if (children.remove(x)) {
x.parent = null;
return true;
}
return false;
}
/**
Inserts a child at the given position among the other childs.
A child node can only be inside one given parent node, which is indicated by the [parent] property.
If the child is already inside this Document or Element, it will be moved to the new position among the Document or Element's children.
If the child node was previously inside a different node, it will be moved to this Document or Element.
**/
public function insertChild(x:Xml, pos:Int):Void {
ensureElementType();
if (x.parent != null) {
x.parent.children.remove(x);
}
children.insert(pos, x);
x.parent = this;
}
/**
Returns a String representation of the Xml node.
**/
public #if !cppia inline #end function toString():String {
return haxe.xml.Printer.print(this);
}
function new(nodeType:XmlType) {
this.nodeType = nodeType;
children = [];
attributeMap = new Map();
}
inline function ensureElementType() {
if (nodeType != Document && nodeType != Element) {
throw 'Bad node type, expected Element or Document but found $nodeType';
}
}
}

View File

@ -0,0 +1,31 @@
/*
* 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 cpp;
extern class ArrayBase {
// Length is number of elements
var length(default, null):Int;
function getElementSize():Int;
function getByteCount():Int;
function getBase():RawPointer<Char>;
}

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 cpp;
@:scalar @:coreType
extern abstract AtomicInt from(Int) to(Int) {
/**
Returns true if exchange took place.
**/
@:native("_hx_atomic_exchange_if")
public static function exchangeIf(ioValue:Pointer<AtomicInt>, test:Int, newVal:Int):Bool;
/**
Returns value before increment.
**/
@:native("_hx_atomic_inc")
public static function atomicInc(ioValue:Pointer<AtomicInt>):Int;
/**
Returns value before decrement.
**/
@:native("_hx_atomic_dec")
public static function atomicDec(ioValue:Pointer<AtomicInt>):Int;
}

View File

@ -0,0 +1,25 @@
/*
* 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 cpp;
extern class AutoCast {}

View File

@ -0,0 +1,72 @@
/*
* 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 cpp;
@:noPackageRestrict @:callable
typedef CallableData<T> = T;
/**
The generator intercepts this type and converts it to a cpp.Function<T> on cpp.
**/
@:noPackageRestrict
@:callable
#if cpp
extern
#end
abstract Callable<T>(CallableData<T>) {
inline public function new(inValue:T)
this = inValue;
public var call(get, never):CallableData<T>;
inline function get_call():CallableData<T>
return this;
#if cpp
@:from
inline static public function fromFunction<F>(func:Function<F, cpp.abi.Abi>):Callable<F>
return new Callable<F>(cast func);
@:to
inline public function toFunction():Function<T, cpp.abi.Abi>
return cast this;
inline public static function getProcAddress<T, ABI:cpp.abi.Abi>(inModule:String, inFunction:String):Function<T, ABI>
return Function.getProcAddress(inModule, inFunction);
inline public static function fromStaticFunction<T>(inStaticFunction:T):Callable<T>
return Function.fromStaticFunction(inStaticFunction);
inline public function lt(inOther:Callable<T>):Bool
return toFunction().lt(inOther.toFunction());
inline public function leq(inOther:Callable<T>):Bool
return toFunction().leq(inOther.toFunction());
inline public function gt(inOther:Callable<T>):Bool
return toFunction().gt(inOther.toFunction());
inline public function geq(inOther:Callable<T>):Bool
return toFunction().geq(inOther.toFunction());
#end
}

View File

@ -0,0 +1,36 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package cpp;
abstract CastCharStar(RawPointer<Char>) to(RawPointer<Char>) {
inline function new(s:String)
this = cast untyped s.__s;
@:from
static public inline function fromString(s:String)
return new CastCharStar(s);
@:to
public inline function toPointer()
return this;
}

View File

@ -0,0 +1,25 @@
/*
* 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 cpp;
@:coreType @:notNull @:runtimeValue abstract Char from Int to Int {}

View File

@ -0,0 +1,38 @@
/*
* 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 cpp;
extern abstract ConstCharStar(RawConstPointer<Char>) to(RawConstPointer<Char>) {
inline function new(s:String)
this = untyped s.__s;
@:from
static public inline function fromString(s:String):ConstCharStar
return new ConstCharStar(s);
@:to extern public inline function toString():String
return new String(untyped this);
@:to extern public inline function toPointer():RawConstPointer<Char>
return this;
}

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 cpp;
@:coreType @:include("cpp/Pointer.h") @:native("cpp.Pointer") @:semantics(variable)
extern class ConstPointer<T> {
// ptr actually returns the pointer - not strictly a 'T' - for pointers to smart pointers
// Use value or ref to get dereferenced value
var ptr:Star<T>;
var value(get, never):T;
// Typecast to non-const
var raw(get, never):RawPointer<T>;
// const version
var constRaw(get, never):RawConstPointer<T>;
function get_value():Reference<T>;
function get_constRaw():RawConstPointer<T>;
function get_raw():RawPointer<T>;
function lt(inOther:ConstPointer<T>):Bool;
function leq(inOther:ConstPointer<T>):Bool;
function gt(inOther:ConstPointer<T>):Bool;
function geq(inOther:ConstPointer<T>):Bool;
function setRaw<O>(ptr:RawPointer<O>):Void;
static function fromRaw<T>(ptr:RawConstPointer<T>):ConstPointer<T>;
@:native("::cpp::Pointer_obj::fromRaw")
static function fromStar<T>(star:Star<T>):ConstPointer<T>;
static function fromPointer<T>(inNativePointer:Dynamic):ConstPointer<T>;
function reinterpret<Other>():Pointer<Other>;
function rawCast<Other>():RawPointer<Other>;
function at(inIndex:Int):Reference<T>;
function inc():ConstPointer<T>;
function dec():ConstPointer<T>;
function incBy(inT:Int):ConstPointer<T>;
function decBy(inT:Int):ConstPointer<T>;
function add(inT:Int):ConstPointer<T>;
function sub(inT:Int):ConstPointer<T>;
function postIncVal():Reference<T>;
}

View File

@ -0,0 +1,29 @@
/*
* 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 cpp;
/**
Allows haxe to type the result correctly, and hxcpp can recognise this uses
the correct type.
**/
typedef ConstStar<T> = Null<T>;

View File

@ -0,0 +1,60 @@
/*
* 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 cpp;
@:native("hx.EnumBase")
extern class EnumBase {
#if (hxcpp_api_level >= 330)
function _hx_getIndex():Int;
function _hx_getTag():String;
function _hx_getParamCount():Int;
function _hx_getParamI(inIndex:Int):Dynamic;
function _hx_getParameters():Array<Dynamic>;
inline function getIndex():Int
return _hx_getIndex();
inline function getTag():String
return _hx_getTag();
inline function getParamCount():Int
return _hx_getParamCount();
inline function getParamI(inIndex:Int):Dynamic
return _hx_getParamI(inIndex);
inline function getParameters():Array<Dynamic>
return _hx_getParameters();
#else
function __EnumParams():Array<Dynamic>;
function __Tag():String;
function __Index():Int;
inline function _hx_getIndex():Int
return untyped __Index();
inline function _hx_getTag():String
return untyped __Tag();
inline function _hx_getParamCount():Int
return untyped __EnumParams() == null ? 0 : __EnumParams().length;
inline function _hx_getParamI(inIndex:Int):Dynamic
return untyped __EnumParams()[inIndex];
inline function _hx_getParameters():Array<Dynamic>
return __EnumParams() == null ? [] : __EnumParams();
#end
}

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 cpp;
extern class ErrorConstants {
@:native("HX_INVALID_CAST")
static var invalidCast:Dynamic;
@:native("HX_INDEX_OUT_OF_BOUNDS")
static var indexOutOfBounds:Dynamic;
@:native("HX_INVALID_OBJECT")
static var invalidObject:Dynamic;
@:native("HX_INVALID_ARG_COUNT")
static var invalidArgCount:Dynamic;
@:native("HX_NULL_FUNCTION_POINTER")
static var nullFunctionPointer:Dynamic;
}

View File

@ -0,0 +1,27 @@
/*
* 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 cpp;
@:include("stdio.h")
@:native(" ::cpp::Pointer<FILE>")
extern class FILE {}

View File

@ -0,0 +1,28 @@
/*
* 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 cpp;
extern class FastIterator<T> {
function hasNext():Bool;
function next():T;
}

View File

@ -0,0 +1,36 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package cpp;
/**
This is just a helper class. It is not actually required to inherit from this
to use `NativeGc.addFinalizable(this,inPin)`, only a function called
`finalize` is needed.
**/
class Finalizable {
public function new(inPin = false) {
NativeGc.addFinalizable(this, inPin);
}
public function finalize():Void {}
}

View File

@ -0,0 +1,25 @@
/*
* 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 cpp;
@:coreType @:notNull @:runtimeValue abstract Float32 from Float to Float {}

View File

@ -0,0 +1,25 @@
/*
* 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 cpp;
@:coreType @:notNull @:runtimeValue abstract Float64 from Float to Float {}

View File

@ -0,0 +1,60 @@
/*
* 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 cpp;
@:callable
typedef FunctionData<T, ABI> = T;
@:include("cpp/Pointer.h") @:callable
extern abstract Function<T, ABI:cpp.abi.Abi>(FunctionData<T, ABI>) {
inline public function new(inValue:T)
this = inValue;
// Legacy Api
public var call(get, never):FunctionData<T, ABI>;
inline function get_call():FunctionData<T, ABI>
return this;
@:native("::cpp::Function_obj::getProcAddress")
extern static function nativeGetProcAddress<T, ABI:cpp.abi.Abi>(inModule:String, inFunction:String):AutoCast;
inline public static function getProcAddress<T, ABI:cpp.abi.Abi>(inModule:String, inFunction:String):Function<T, ABI> {
return cast nativeGetProcAddress(inModule, inFunction);
}
@:native("::cpp::Function_obj::fromStaticFunction")
extern static function nativeFromStaticFunction<T>(inStaticFunction:T):AutoCast;
inline public static function fromStaticFunction<T>(inStaticFunction:T):Callable<T> {
return cast nativeFromStaticFunction(inStaticFunction);
}
extern public function lt(inOther:Function<T, ABI>):Bool;
extern public function leq(inOther:Function<T, ABI>):Bool;
extern public function gt(inOther:Function<T, ABI>):Bool;
extern public function geq(inOther:Function<T, ABI>):Bool;
}

View File

@ -0,0 +1,25 @@
/*
* 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 cpp;
@:coreType @:notNull @:runtimeValue abstract Int16 from Int to Int {}

View File

@ -0,0 +1,25 @@
/*
* 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 cpp;
@:coreType @:notNull @:runtimeValue abstract Int32 from Int to Int {}

View File

@ -0,0 +1,35 @@
/*
* 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 cpp;
@:coreType @:notNull @:runtimeValue abstract Int64 from Int to Int {
@:to
#if !cppia inline #end function toInt64():haxe.Int64 {
return cast this;
}
@:from
static #if !cppia inline #end function ofInt64(x:haxe.Int64):Int64 {
return cast x;
}
}

View File

@ -0,0 +1,25 @@
/*
* 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 cpp;
@:coreType @:notNull @:runtimeValue abstract Int8 from Int to Int {}

View File

@ -0,0 +1,149 @@
/*
* 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 cpp;
/**
Platform-specific Cpp Library. Provides some platform-specific functions
for the C++ target, such as conversion from Haxe types to native types
and vice-versa.
**/
class Lib {
/**
Load and return a Cpp primitive from a DLL library.
**/
public static function load(lib:String, prim:String, nargs:Int):Dynamic {
#if (iphone || emscripten)
return loadLazy(lib, prim, nargs);
#else
return untyped __global__.__loadprim(lib, prim, nargs);
#end
}
/**
Unloaded all dynamic libraries in reverse order of loading.
Returns the number of libraries unloaded.
**/
public static function unloadAllLibraries():Int {
return untyped __global__.__hxcpp_unload_all_libraries();
}
public static function _loadPrime(lib:String, prim:String, signature:String, quietFail = false):Dynamic {
var factory:Callable<ConstCharStar->Object> = untyped __global__.__hxcpp_cast_get_proc_address(lib, prim + "__prime", quietFail);
if (factory != null) {
var func:Dynamic = factory.call(signature);
if (func == null && !quietFail)
throw '$prim does not have signature $signature';
return func;
}
return null;
}
/**
Tries to load, and always returns a valid function, but the function may throw
if called.
**/
public static function loadLazy(lib:String, prim:String, nargs:Int):Dynamic {
try {
return untyped __global__.__loadprim(lib, prim, nargs);
} catch (e:Dynamic) {
return switch (nargs) {
case 0: () -> throw e;
case 2: (_, _) -> throw e;
case 3: (_, _, _) -> throw e;
case 4: (_, _, _, _) -> throw e;
case 5: (_, _, _, _, _) -> throw e;
default: _ -> throw e;
};
}
return null;
}
@:noDebug @:native("HX_STACK_DO_RETHROW")
extern static function do_rethrow(inExp:Dynamic);
@:noDebug #if (!cppia) inline #end
public static function rethrow(inExp:Dynamic) {
do_rethrow(inExp);
}
public static function stringReference(inBytes:haxe.io.Bytes):String {
var result:String = "";
untyped __global__.__hxcpp_string_of_bytes(inBytes.b, result, 0, inBytes.length, true);
return result;
}
public static function pushDllSearchPath(inPath:String):Void
untyped __global__.__hxcpp_push_dll_path(inPath);
public static function getDllExtension():String
return untyped __global__.__hxcpp_get_dll_extension();
public static function getBinDirectory():String
return untyped __global__.__hxcpp_get_bin_dir();
/**
Returns bytes referencing the content of a string.
Use with extreme caution - changing constant strings will crash.
Changing one string can cause others to change unexpectedly.
Only really safe if you are using it read-only or if it comes from stringReference above
**/
public inline static function bytesReference(s:String):haxe.io.Bytes {
var bytes = new haxe.io.BytesData();
untyped bytes.__unsafeStringReference(s);
return haxe.io.Bytes.ofData(bytes);
}
/**
Print the specified value on the default output.
**/
public static function print(v:Dynamic):Void {
untyped __global__.__hxcpp_print(v);
}
/**
This function is used to make porting from neko to cpp easy.
It does not need to do anything because the c-code can work with any Dynamic
**/
public static function haxeToNeko(v:Dynamic):Dynamic {
return v;
}
/**
This function is used to make porting from neko to cpp easy.
It does not need to do anything because the c-code can work with any Dynamic
**/
public static function nekoToHaxe(v:Dynamic):Dynamic {
return v;
}
/**
Print the specified value on the default output followed by a newline character.
**/
public static function println(v:Dynamic):Void {
untyped __global__.__hxcpp_println(v);
}
public static function setFloatFormat(inFormat:String):Void {
untyped __global__.__hxcpp_set_float_format(inFormat);
}
}

View File

@ -0,0 +1,103 @@
/*
* 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 cpp;
@:include("stdlib.h")
extern class Native {
@:native("malloc")
static function nativeMalloc(bytes:Int):cpp.Star<cpp.Void>;
@:native("calloc")
static function nativeCalloc(bytes:Int):cpp.Star<cpp.Void>;
@:native("realloc")
static function nativeRealloc(inPtr:cpp.Star<cpp.Void>, bytes:Int):cpp.RawPointer<cpp.Void>;
@:native("free")
static function nativeFree(ptr:cpp.Star<cpp.Void>):Void;
@:native("memcpy")
static function nativeMemcpy(dest:cpp.Star<cpp.Void>, src:cpp.Star<cpp.Void>, bytes:Int):Void;
@:native("::hx::ClassSizeOf") @:templatedCall
static function sizeof<T>(t:T):Int;
#if !cppia
@:native("::hx::Dereference")
static function star<T>(ptr:cpp.Star<T>):cpp.Reference<T>;
@:generic
static inline function set<T>(ptr:cpp.Star<T>, value:T):Void {
var ref:cpp.Reference<T> = star(ptr);
ref = value;
}
@:generic
static inline function get<T>(ptr:cpp.Star<T>):T {
var ref:cpp.Reference<T> = star(ptr);
return ref;
}
@:generic
static inline function memcpy<DEST, SRC>(dest:cpp.Star<DEST>, src:cpp.Star<SRC>, bytes:Int):Void
nativeMemcpy(cast dest, cast src, bytes);
@:generic
static inline function malloc<T>(bytes:Int):cpp.Star<T>
return cast nativeMalloc(bytes);
@:generic
static inline function calloc<T>(bytes:Int):cpp.Star<T>
return cast nativeCalloc(bytes);
@:generic
static inline function realloc<T>(ioPtr:cpp.Star<T>, bytes:Int):cpp.Star<T>
return cast nativeRealloc(cast ioPtr, bytes);
@:generic
static inline function free<T>(ptr:cpp.Star<T>):Void {
if (ptr != null)
nativeFree(cast ptr);
}
@:native("::hx::StarOf")
static function addressOf<T>(inVariable:Reference<T>):Star<T>;
#else
static inline function addressOf<T>(inVariable:Reference<T>):Star<T> {
throw "Native.addressOf not available in cppia";
}
static inline function star<T>(ptr:cpp.Star<T>):cpp.Reference<T> {
throw "Native.star not available in cppia";
}
static inline function set<T>(ptr:cpp.Star<T>, value:T):Void {
throw "Native.set not available in cppia";
}
static inline function get<T>(ptr:cpp.Star<T>):T {
throw "Native.get not available in cppia";
var d:Dynamic = null;
return d;
}
static function memcpy<DEST, SRC>(dest:cpp.Star<DEST>, src:cpp.Star<SRC>, bytes:Int):Void;
static function malloc<T>(bytes:Int):cpp.Star<T>;
static function calloc<T>(bytes:Int):cpp.Star<T>;
static function realloc<T>(ioPtr:cpp.Star<T>, bytes:Int):cpp.Star<T>;
static function free<T>(ptr:cpp.Star<T>):Void;
#end
}

View File

@ -0,0 +1,31 @@
/*
* 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 cpp;
extern class NativeArc {
@:native("(__bridge_transfer id)")
static function _bridgeTransfer<T>(ptr:cpp.RawPointer<cpp.Void>):cpp.RawPointer<T>;
static inline function bridgeTransfer<T>(ptr:cpp.RawPointer<cpp.Void>):T
return cast _bridgeTransfer(ptr);
}

View File

@ -0,0 +1,100 @@
/*
* 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 cpp;
extern class NativeArray {
#if cppia
static inline function create<T>(length:Int):Array<T> {
var result = new Array<T>();
NativeArray.setSize(result, length);
return result;
}
#else
@:native("_hx_create_array_length")
static function create<T>(length:Int):Array<T>;
#end
static inline function blit<T>(ioDestArray:Array<T>, inDestElement:Int, inSourceArray:Array<T>, inSourceElement:Int, inElementCount:Int):Void {
untyped ioDestArray.blit(inDestElement, inSourceArray, inSourceElement, inElementCount);
};
static inline function getBase(inArray:Array<Dynamic>):ArrayBase {
return untyped inArray;
}
@:nativeStaticExtension
static function reserve<T>(inArray:Array<T>, inElements:Int):Void;
@:nativeStaticExtension
static function capacity<T>(inArray:Array<T>):Int;
@:nativeStaticExtension
static function getElementSize<T>(inArray:Array<T>):Int;
static inline function address<T>(inArray:Array<T>, inIndex:Int):Pointer<T> {
return Pointer.arrayElem(inArray, inIndex);
}
@:nativeStaticExtension
static function setData<T>(inArray:Array<T>, inData:Pointer<T>, inElementCount:Int):Void;
@:nativeStaticExtension
static function setUnmanagedData<T>(inArray:Array<T>, inData:ConstPointer<T>, inElementCount:Int):Void;
@:nativeStaticExtension
static function zero<T>(ioDestArray:Array<T>, ?inFirst:Int, ?inElements:Int):Void;
@:nativeStaticExtension
static function removeAt<T>(ioDestArray:Array<T>, inIndex:Int):Void;
@:nativeStaticExtension
static function memcmp<T>(inArrayA:Array<T>, inArrayB:Array<T>):Int;
@:native("_hx_reslove_virtual_array")
static function resolveVirtualArray(inArray:Array<Dynamic>):Dynamic;
#if cppia
static inline function unsafeGet<T>(inDestArray:Array<T>, inIndex:Int):T {
return untyped inDestArray.__unsafe_get(inIndex);
}
static inline function unsafeSet<T>(ioDestArray:Array<T>, inIndex:Int, inValue:T):T {
return untyped ioDestArray.__unsafe_set(inIndex, inValue);
}
static inline function setSize<T>(ioArray:Array<T>, inSize:Int):Array<T> {
return untyped ioArray.__SetSizeExact(inSize);
}
#else
@:native("_hx_array_unsafe_get")
static function unsafeGet<T>(inDestArray:Array<T>, inIndex:Int):T;
@:native("_hx_array_unsafe_set")
static inline function unsafeSet<T>(ioDestArray:Array<T>, inIndex:Int, inValue:T):T {
return untyped ioDestArray.__unsafe_set(inIndex, inValue);
}
@:native("_hx_array_set_size_exact")
static function setSize<T>(ioArray:Array<T>, inSize:Int):Array<T>;
#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 cpp;
@:buildXml('<include name="${HXCPP}/src/hx/libs/std/Build.xml"/>')
extern class NativeFile {
@:native("_hx_std_file_open")
extern static function file_open(fname:String, r:String):Dynamic;
@:native("_hx_std_file_close")
extern static function file_close(handle:Dynamic):Void;
@:native("_hx_std_file_write")
extern static function file_write(handle:Dynamic, s:haxe.io.BytesData, p:Int, n:Int):Int;
@:native("_hx_std_file_write_char")
extern static function file_write_char(handle:Dynamic, c:Int):Void;
@:native("_hx_std_file_read")
extern static function file_read(handle:Dynamic, s:haxe.io.BytesData, p:Int, n:Int):Int;
@:native("_hx_std_file_read_char")
extern static function file_read_char(handle:Dynamic):Int;
@:native("_hx_std_file_seek")
extern static function file_seek(handle:Dynamic, pos:Int, kind:Int):Void;
@:native("_hx_std_file_tell")
extern static function file_tell(handle:Dynamic):Int;
@:native("_hx_std_file_eof")
extern static function file_eof(handle:Dynamic):Bool;
@:native("_hx_std_file_flush")
extern static function file_flush(handle:Dynamic):Void;
@:native("_hx_std_file_contents_string")
extern static function file_contents_string(name:String):String;
@:native("_hx_std_file_contents_bytes")
extern static function file_contents_bytes(name:String):haxe.io.BytesData;
@:native("_hx_std_file_stdin")
extern static function file_stdin():Dynamic;
@:native("_hx_std_file_stdout")
extern static function file_stdout():Dynamic;
@:native("_hx_std_file_stderr")
extern static function file_stderr():Dynamic;
}

View File

@ -0,0 +1,65 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package cpp;
extern class NativeGc {
@:native("__hxcpp_gc_mem_info")
static function memInfo(inWhatInfo:Int):Float;
@:native("_hx_allocate_extended") @:templatedCall
static function allocateExtended<T>(cls:Class<T>, size:Int):T;
@:native("_hx_add_finalizable")
static function addFinalizable(instance:{function finalize():Void;}, inPin:Bool):Void;
@:native("::hx::InternalNew")
static function allocGcBytesRaw(inBytes:Int, isContainer:Bool):RawPointer<cpp.Void>;
inline static function allocGcBytes(inBytes:Int):Pointer<cpp.Void> {
return Pointer.fromRaw(allocGcBytesRaw(inBytes, false));
}
@:native("__hxcpp_enable") extern static function enable(inEnable:Bool):Void;
@:native("__hxcpp_collect") extern static function run(major:Bool):Void;
@:native("__hxcpp_gc_compact") extern static function compact():Void;
@:native("__hxcpp_gc_trace") extern static function nativeTrace(sought:Class<Dynamic>, printInstances:Bool):Int;
@:native("__hxcpp_gc_do_not_kill") extern static function doNotKill(inObject:Dynamic):Void;
@:native("__hxcpp_get_next_zombie") extern static function getNextZombie():Dynamic;
@:native("__hxcpp_gc_safe_point") extern static function safePoint():Void;
@:native("__hxcpp_enter_gc_free_zone") extern static function enterGCFreeZone():Void;
@:native("__hxcpp_exit_gc_free_zone") extern static function exitGCFreeZone():Void;
@:native("__hxcpp_set_minimum_free_space") extern static function setMinimumFreeSpace(inBytes:Int):Void;
@:native("__hxcpp_set_target_free_space_percentage") extern static function setTargetFreeSpacePercentage(inPercentage:Int):Void;
@:native("__hxcpp_set_minimum_working_memory") extern static function setMinimumWorkingMemory(inBytes:Int):Void;
}

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 cpp;
@:noPackageRestrict
extern class NativeMath {
#if (cpp && !cppia)
@:native("_hx_idiv")
static function idiv(num:Int, denom:Int):Int;
@:native("_hx_imod")
static function imod(num:Int, denom:Int):Int;
@:native("_hx_cast_int")
static function castInt(f:Float):Int;
@:native("_hx_fast_floor")
static function fastInt(f:Float):Int;
#else
static inline function imod(num:Int, denom:Int):Int
return num % denom;
static inline function idiv(num:Int, denom:Int):Int
return Std.int(num / denom);
static inline function castInt(f:Float):Int
return Std.int(f);
static inline function fastInt(f:Float):Int
return Std.int(f);
#end
}

View File

@ -0,0 +1,56 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package cpp;
@:buildXml('<include name="${HXCPP}/src/hx/libs/std/Build.xml"/>')
extern class NativeProcess {
@:native("_hx_std_process_run")
static function process_run(cmd:String, vargs:Array<String>):Dynamic;
@:native("_hx_std_process_run")
static function process_run_with_show(cmd:String, vargs:Array<String>, inShow:Int):Dynamic;
@:native("_hx_std_process_stdout_read")
static function process_stdout_read(handle:Dynamic, buf:haxe.io.BytesData, pos:Int, len:Int):Int;
@:native("_hx_std_process_stderr_read")
static function process_stderr_read(handle:Dynamic, buf:haxe.io.BytesData, pos:Int, len:Int):Int;
@:native("_hx_std_process_stdin_write")
static function process_stdin_write(handle:Dynamic, buf:haxe.io.BytesData, pos:Int, len:Int):Int;
@:native("_hx_std_process_stdin_close")
static function process_stdin_close(handle:Dynamic):Void;
@:native("_hx_std_process_exit")
static function process_exit(handle:Dynamic):Int;
@:native("_hx_std_process_pid")
static function process_pid(handle:Dynamic):Int;
@:native("_hx_std_process_kill")
static function process_kill(handle:Dynamic):Void;
@:native("_hx_std_process_close")
static function process_close(handle:Dynamic):Void;
}

View File

@ -0,0 +1,38 @@
/*
* 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 cpp;
@:buildXml('<include name="${HXCPP}/src/hx/libs/std/Build.xml"/>')
extern class NativeRandom {
@:native("_hx_std_random_new")
static function random_new():Dynamic;
@:native("_hx_std_random_set_seed")
static function random_set_seed(handle:Dynamic, v:Int):Void;
@:native("_hx_std_random_int")
static function random_int(handle:Dynamic, max:Int):Int;
@:native("_hx_std_random_float")
static function random_float(handle:Dynamic):Float;
}

View File

@ -0,0 +1,145 @@
/*
* 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 cpp;
import sys.net.Socket;
@:buildXml('<include name="${HXCPP}/src/hx/libs/std/Build.xml"/>')
extern class NativeSocket {
@:native("_hx_std_socket_init")
static function socket_init():Void;
@:native("_hx_std_socket_new")
static function socket_new(udp:Bool):Dynamic;
@:native("_hx_std_socket_new")
static function socket_new_ip(udp:Bool, ipv6:Bool):Dynamic;
@:native("_hx_std_socket_close")
static function socket_close(handle:Dynamic):Void;
@:native("_hx_std_socket_bind")
static function socket_bind(o:Dynamic, host:Int, port:Int):Void;
@:native("_hx_std_socket_bind_ipv6")
static function socket_bind_ipv6(o:Dynamic, host:haxe.io.BytesData, port:Int):Void;
@:native("_hx_std_socket_send_char")
static function socket_send_char(o:Dynamic, c:Int):Void;
@:native("_hx_std_socket_send")
static function socket_send(o:Dynamic, buf:haxe.io.BytesData, p:Int, l:Int):Int;
@:native("_hx_std_socket_recv")
static function socket_recv(o:Dynamic, buf:haxe.io.BytesData, p:Int, l:Int):Int;
@:native("_hx_std_socket_recv_char")
static function socket_recv_char(o:Dynamic):Int;
@:native("_hx_std_socket_write")
static function socket_write(o:Dynamic, buf:haxe.io.BytesData):Void;
@:native("_hx_std_socket_read")
static function socket_read(o:Dynamic):haxe.io.BytesData;
@:native("_hx_std_host_resolve_ipv6")
static function host_resolve_ipv6(host:String):haxe.io.BytesData;
@:native("_hx_std_host_resolve")
static function host_resolve(host:String):Int;
@:native("_hx_std_host_to_string")
static function host_to_string(ip:Int):String;
@:native("_hx_std_host_to_string_ipv6")
static function host_to_string_ipv6(ipv6:haxe.io.BytesData):String;
@:native("_hx_std_host_reverse")
static function host_reverse(host:Int):String;
@:native("_hx_std_host_reverse_ipv6")
static function host_reverse_ipv6(ipv6:haxe.io.BytesData):String;
@:native("_hx_std_host_local")
static function host_local():String;
inline static function host_local_ipv6():String
return "::1";
@:native("_hx_std_socket_connect")
static function socket_connect(o:Dynamic, host:Int, port:Int):Void;
@:native("_hx_std_socket_connect_ipv6")
static function socket_connect_ipv6(o:Dynamic, host:haxe.io.BytesData, port:Int):Void;
@:native("_hx_std_socket_listen")
static function socket_listen(o:Dynamic, n:Int):Void;
@:native("_hx_std_socket_select")
static function socket_select(rs:Array<Dynamic>, ws:Array<Dynamic>, es:Array<Dynamic>, timeout:Dynamic):Array<Dynamic>;
@:native("_hx_std_socket_fast_select")
static function socket_fast_select(rs:Array<Dynamic>, ws:Array<Dynamic>, es:Array<Dynamic>, timeout:Dynamic):Void;
@:native("_hx_std_socket_accept")
static function socket_accept(o:Dynamic):Dynamic;
@:native("_hx_std_socket_peer")
static function socket_peer(o:Dynamic):Array<Int>;
@:native("_hx_std_socket_host")
static function socket_host(o:Dynamic):Array<Int>;
@:native("_hx_std_socket_set_timeout")
static function socket_set_timeout(o:Dynamic, t:Dynamic):Void;
@:native("_hx_std_socket_shutdown")
static function socket_shutdown(o:Dynamic, r:Bool, w:Bool):Void;
@:native("_hx_std_socket_set_blocking")
static function socket_set_blocking(o:Dynamic, b:Bool):Void;
@:native("_hx_std_socket_set_fast_send")
static function socket_set_fast_send(o:Dynamic, b:Bool):Void;
@:native("_hx_std_socket_set_broadcast")
static function socket_set_broadcast(o:Dynamic, b:Bool):Void;
@:native("_hx_std_socket_poll_alloc")
static function socket_poll_alloc(nsocks:Int):Dynamic;
@:native("_hx_std_socket_poll_prepare")
static function socket_poll_prepare(pdata:Dynamic, rsocks:Array<Socket>, wsocks:Array<Socket>):Array<Array<Int>>;
@:native("_hx_std_socket_poll_events")
static function socket_poll_events(pdata:Dynamic, timeout:Float):Void;
@:native("_hx_std_socket_poll")
static function socket_poll(socks:Array<Socket>, pdata:Dynamic, timeout:Float):Array<Socket>;
@:native("_hx_std_socket_send_to")
static function socket_send_to(o:Dynamic, buf:haxe.io.BytesData, p:Int, l:Int, inAddr:Dynamic):Int;
@:native("_hx_std_socket_recv_from")
static function socket_recv_from(o:Dynamic, buf:haxe.io.BytesData, p:Int, l:Int, outAddr:Dynamic):Int;
}

View File

@ -0,0 +1,137 @@
/*
* 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 cpp;
@:buildXml('<include name="${HXCPP}/src/hx/libs/ssl/Build.xml"/>')
extern class NativeSsl {
@:native("_hx_ssl_debug_set")
static function ssl_debug_set(int:Int):Void;
@:native("_hx_ssl_new")
static function ssl_new(conf:Dynamic):Dynamic;
@:native("_hx_ssl_close")
static function ssl_close(ctx:Dynamic):Void;
@:native("_hx_ssl_handshake")
static function ssl_handshake(ctx:Dynamic):Void;
@:native("_hx_ssl_set_socket")
static function ssl_set_socket(ctx:Dynamic, socket:Dynamic):Void;
@:native("_hx_ssl_set_hostname")
static function ssl_set_hostname(ctx:Dynamic, hostname:String):Void;
@:native("_hx_ssl_get_peer_certificate")
static function ssl_get_peer_certificate(ctx:Dynamic):Dynamic;
@:native("_hx_ssl_get_verify_result")
static function ssl_get_verify_result(ctx:Dynamic):Bool;
@:native("_hx_ssl_send_char")
static function ssl_send_char(ctx:Dynamic, char:Int):Void;
@:native("_hx_ssl_send")
static function ssl_send(ctx:Dynamic, buf:haxe.io.BytesData, p:Int, l:Int):Int;
@:native("_hx_ssl_write")
static function ssl_write(ctx:Dynamic, data:haxe.io.BytesData):Void;
@:native("_hx_ssl_recv_char")
static function ssl_recv_char(ctx:Dynamic):Int;
@:native("_hx_ssl_recv")
static function ssl_recv(ctx:Dynamic, buf:haxe.io.BytesData, p:Int, l:Int):Int;
@:native("_hx_ssl_read")
static function ssl_read(ctx:Dynamic):haxe.io.BytesData;
@:native("_hx_ssl_conf_new")
static function conf_new(server:Bool):Dynamic;
@:native("_hx_ssl_conf_close")
static function conf_close(conf:Dynamic):Void;
@:native("_hx_ssl_conf_set_ca")
static function conf_set_ca(conf:Dynamic, cert:Dynamic):Void;
@:native("_hx_ssl_conf_set_verify")
static function conf_set_verify(conf:Dynamic, mode:Int):Void;
@:native("_hx_ssl_conf_set_cert")
static function conf_set_cert(conf:Dynamic, cert:Dynamic, pkey:Dynamic):Void;
@:native("_hx_ssl_conf_set_servername_callback")
static function conf_set_servername_callback(conf:Dynamic, cb:Dynamic):Void;
@:native("_hx_ssl_cert_load_defaults")
static function cert_load_defaults():Dynamic;
@:native("_hx_ssl_cert_load_file")
static function cert_load_file(file:String):Dynamic;
@:native("_hx_ssl_cert_load_path")
static function cert_load_path(path:String):Dynamic;
@:native("_hx_ssl_cert_get_subject")
static function cert_get_subject(cert:Dynamic, field:String):String;
@:native("_hx_ssl_cert_get_issuer")
static function cert_get_issuer(cert:Dynamic, field:String):String;
@:native("_hx_ssl_cert_get_altnames")
static function cert_get_altnames(cert:Dynamic):Array<String>;
@:native("_hx_ssl_cert_get_notbefore")
static function cert_get_notbefore(cert:Dynamic):Array<Int>;
@:native("_hx_ssl_cert_get_notafter")
static function cert_get_notafter(cert:Dynamic):Array<Int>;
@:native("_hx_ssl_cert_get_next")
static function cert_get_next(cert:Dynamic):Dynamic;
@:native("_hx_ssl_cert_add_pem")
static function cert_add_pem(cert:Dynamic, data:String):Dynamic;
@:native("_hx_ssl_cert_add_der")
static function cert_add_der(cert:Dynamic, data:haxe.io.BytesData):Dynamic;
@:native("_hx_ssl_key_from_der")
static function key_from_der(data:haxe.io.BytesData, pub:Bool):Dynamic;
@:native("_hx_ssl_key_from_pem")
static function key_from_pem(data:String, pub:Bool, pass:String):Dynamic;
@:native("_hx_ssl_dgst_make")
static function dgst_make(data:haxe.io.BytesData, alg:String):haxe.io.BytesData;
@:native("_hx_ssl_dgst_sign")
static function dgst_sign(data:haxe.io.BytesData, key:Dynamic, alg:String):haxe.io.BytesData;
@:native("_hx_ssl_dgst_verify")
static function dgst_verify(data:haxe.io.BytesData, sign:haxe.io.BytesData, key:Dynamic, alg:String):Bool;
@:native("_hx_ssl_init")
static function init():Void;
}

View File

@ -0,0 +1,73 @@
/*
* 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 cpp;
extern class NativeString {
static inline function raw(inString:String):RawConstPointer<Char> {
return untyped inString.raw_ptr();
}
static inline function c_str(inString:String):ConstPointer<Char> {
return cpp.ConstPointer.fromPointer(untyped inString.c_str());
}
static inline function fromPointer(inPtr:ConstPointer<Char>):String {
return untyped __global__.String(inPtr.ptr);
}
static inline function fromGcPointer(inPtr:ConstPointer<Char>, inLen:Int):String {
return untyped __global__.String(inPtr.ptr, inLen);
}
@:native("__hxcpp_parse_float")
public static function parseFloat(inString:String):Float;
@:native("__hxcpp_parse_substr_float")
public static function parseSubstrFloat(inString:String,start:Int, length:Int):Float;
// Will return 0 for invalid string
@:native("__hxcpp_parse_substr_int")
public static function parseInt(inString:String):Int;
// Will return 0 for invalid string
@:native("__hxcpp_parse_substr_int")
public static function parseSubstrInt(inString:String,start:Int, length:Int):Int;
@:native("_hx_string_compare")
static function compare(inString0:String, inString1:String):Int;
@:native("_hx_utf8_char_code_at")
static function utf8CharCodeAt(inString:String, inIndex:Int):Int;
@:native("_hx_utf8_length")
static function utf8Length(inString:String):Int;
@:native("_hx_utf8_is_valid")
static function utf8IsValid(inString:String):Bool;
@:native("_hx_utf8_sub")
static function utf8Sub(inString:String, charStart:Int, inLen:Int):String;
@:native("_hx_string_create")
static function fromPointerLen(inPtr:ConstPointer<Char>, len:Int):String;
@:native("_hx_utf8_decode_advance")
static function utf8DecodeAdvance(reference:Char):Int;
}

View File

@ -0,0 +1,107 @@
/*
* 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 cpp;
@:buildXml('<include name="${HXCPP}/src/hx/libs/std/Build.xml"/>')
extern class NativeSys {
@:native("__hxcpp_print")
static function print(v:Dynamic):Void;
@:native("__hxcpp_println")
static function println(v:Dynamic):Void;
@:native("_hx_std_get_env")
extern static function get_env(v:String):String;
@:native("_hx_std_put_env")
extern static function put_env(e:String, v:String):Void;
@:native("_hx_std_sys_sleep")
extern static function sys_sleep(f:Float):Void;
@:native("_hx_std_set_time_locale")
extern static function set_time_locale(l:String):Bool;
@:native("_hx_std_get_cwd")
extern static function get_cwd():String;
@:native("_hx_std_set_cwd")
extern static function set_cwd(d:String):Void;
@:native("_hx_std_sys_string")
extern static function sys_string():String;
@:native("_hx_std_sys_is64")
extern static function sys_is64():Bool;
@:native("_hx_std_sys_command")
extern static function sys_command(cmd:String):Int;
@:native("_hx_std_sys_exit")
extern static function sys_exit(code:Int):Void;
@:native("_hx_std_sys_exists")
extern static function sys_exists(path:String):Bool;
@:native("_hx_std_file_delete")
extern static function file_delete(path:String):Void;
@:native("_hx_std_sys_rename")
extern static function sys_rename(path:String, newname:String):Bool;
@:native("_hx_std_sys_stat")
extern static function sys_stat(path:String):Dynamic;
@:native("_hx_std_sys_file_type")
extern static function sys_file_type(path:String):String;
@:native("_hx_std_sys_create_dir")
extern static function sys_create_dir(path:String, mode:Int):Bool;
@:native("_hx_std_sys_remove_dir")
extern static function sys_remove_dir(path:String):Void;
@:native("_hx_std_sys_time")
extern static function sys_time():Float;
@:native("_hx_std_sys_cpu_time")
extern static function sys_cpu_time():Float;
@:native("_hx_std_sys_read_dir")
extern static function sys_read_dir(p:String):Array<String>;
@:native("_hx_std_file_full_path")
extern static function file_full_path(path:String):String;
@:native("_hx_std_sys_exe_path")
extern static function sys_exe_path():String;
@:native("_hx_std_sys_env")
extern static function sys_env():Array<String>;
@:native("_hx_std_sys_getch")
extern static function sys_getch(b:Bool):Int;
@:native("_hx_std_sys_get_pid")
extern static function sys_get_pid():Int;
}

View File

@ -0,0 +1,473 @@
/*
* 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 cpp;
enum abstract XmlType(Int) {
/**
Represents an XML element type.
**/
var Element = 0;
/**
Represents XML parsed character data type.
**/
var PCData = 1;
/**
Represents XML character data type.
**/
var CData = 2;
/**
Represents an XML comment type.
**/
var Comment = 3;
/**
Represents an XML doctype element type.
**/
var DocType = 4;
/**
Represents an XML processing instruction type.
**/
var ProcessingInstruction = 5;
/**
Represents an XML document type.
**/
var Document = 6;
}
class NativeXmlState {
var cur:Xml;
public function new(x:Xml) {
x._children = new Array<Xml>();
cur = x;
}
@:keep
public function xml(name:String, att:Dynamic<String>) {
var x = new Xml();
x._parent = cur;
x.nodeType = Xml.Element;
x._nodeName = name;
x._attributes = att;
x._children = new Array<Xml>();
cur.addChild(x);
cur = x;
}
@:keep
public function cdata(text:String) {
var x = new Xml();
x._parent = cur;
x.nodeType = Xml.CData;
x._nodeValue = text;
cur.addChild(x);
}
@:keep
public function pcdata(text:String) {
var x = new Xml();
x._parent = cur;
x.nodeType = Xml.PCData;
x._nodeValue = text;
cur.addChild(x);
}
@:keep
public function comment(text:String) {
var x = new Xml();
x._parent = cur;
if (text.length > 1 && StringTools.fastCodeAt(text, 0) == 63) {
x.nodeType = Xml.ProcessingInstruction;
text = text.substr(1, text.length - 2);
} else {
x.nodeType = Xml.Comment;
}
x._nodeValue = text;
cur.addChild(x);
}
@:keep
public function doctype(text:String) {
var x = new Xml();
x._parent = cur;
x.nodeType = Xml.DocType;
x._nodeValue = text.substr(1);
cur.addChild(x);
}
@:keep
public function done() {
cur = cur._parent;
}
}
private class NativeXmlIterator {
var cur = 0;
var children:Array<Xml>;
public function new(inChildren:Array<Xml>) {
children = inChildren;
cur = 0;
}
public function hasNext():Bool {
var k = cur;
var l = children.length;
while (k < l) {
if (children[k].nodeType == Xml.Element)
break;
k += 1;
}
cur = k;
return k < l;
}
public function next():Xml {
var k = cur;
var l = children.length;
while (k < l) {
var n = children[k];
k += 1;
if (n.nodeType == Xml.Element) {
cur = k;
return n;
}
}
return null;
}
}
private class NativeXmlNamedIterator {
var cur = 0;
var children:Array<Xml>;
var name:String;
public function new(inChildren:Array<Xml>, inName:String) {
children = inChildren;
name = inName;
cur = 0;
}
public function hasNext():Bool {
var k = cur;
var l = children.length;
while (k < l) {
var n = children[k];
if (n.nodeType == Xml.Element && n._nodeName == name)
break;
k++;
}
cur = k;
return k < l;
}
public function next():Xml {
var k = cur;
var l = children.length;
while (k < l) {
var n = children[k];
k++;
if (n.nodeType == Xml.Element && n._nodeName == name) {
cur = k;
return n;
}
}
return null;
}
}
@:cppInclude("./NativeXmlImport.cpp")
@:allow(cpp.NativeXmlState) @:allow(cpp.NativeXmlIterator) @:allow(cpp.NativeXmlNamedIterator)
class Xml {
static inline var Element = XmlType.Element;
static inline var PCData = XmlType.PCData;
static inline var CData = XmlType.CData;
static inline var Comment = XmlType.Comment;
static inline var DocType = XmlType.DocType;
static inline var ProcessingInstruction = XmlType.ProcessingInstruction;
static inline var Document = XmlType.Document;
private var _nodeName:String;
private var _nodeValue:String;
private var _attributes:Dynamic<String>;
private var _children:Array<Xml>;
private var _parent:Xml;
function new():Void {}
@:native("parse_xml")
extern static function parse_xml(str:String, state:NativeXmlState);
public static function parse(str:String):Xml {
var x = new Xml();
var state = new NativeXmlState(x);
parse_xml(str, state);
x.nodeType = Xml.Document;
return x;
}
public static function createElement(name:String):Xml {
var r = new Xml();
r.nodeType = Xml.Element;
r._nodeName = name;
r._attributes = null;
r._children = new Array();
return r;
}
public static function createPCData(data:String):Xml {
var r = new Xml();
r.nodeType = Xml.PCData;
r._nodeValue = data;
return r;
}
public static function createCData(data:String):Xml {
var r = new Xml();
r.nodeType = Xml.CData;
r._nodeValue = data;
return r;
}
public static function createComment(data:String):Xml {
var r = new Xml();
r.nodeType = Xml.Comment;
r._nodeValue = data;
return r;
}
public static function createDocType(data:String):Xml {
var r = new Xml();
r.nodeType = Xml.DocType;
r._nodeValue = data;
return r;
}
public static function createProcessingInstruction(data:String):Xml {
var r = new Xml();
r.nodeType = Xml.ProcessingInstruction;
r._nodeValue = data;
return r;
}
public static function createDocument():Xml {
var r = new Xml();
r.nodeType = Xml.Document;
r._children = new Array();
return r;
}
public var nodeType(default, null):XmlType;
public var nodeName(get, set):String;
public var nodeValue(get, set):String;
private function get_nodeName():String {
if (nodeType != Xml.Element)
throw "bad nodeType";
return _nodeName;
}
private function set_nodeName(n:String):String {
if (nodeType != Xml.Element)
throw "bad nodeType";
return _nodeName = n;
}
private function get_nodeValue():String {
if (nodeType == Xml.Element || nodeType == Xml.Document)
throw "bad nodeType";
return _nodeValue;
}
private function set_nodeValue(v:String):String {
if (nodeType == Xml.Element || nodeType == Xml.Document)
throw "bad nodeType";
return _nodeValue = v;
}
public var parent(get, null):Xml;
private function get_parent():Xml {
return _parent;
}
public function get(att:String):String {
if (nodeType != Xml.Element)
throw "bad nodeType";
return Reflect.field(_attributes, att);
}
public function set(att:String, value:String):Void {
if (nodeType != Xml.Element)
throw "bad nodeType";
if (_attributes == null)
_attributes = {};
Reflect.setField(_attributes, att, value);
return;
}
public function remove(att:String):Void {
if (nodeType != Xml.Element)
throw "bad nodeType";
Reflect.deleteField(_attributes, att);
return;
}
public function exists(att:String):Bool {
if (nodeType != Xml.Element)
throw "bad nodeType";
return Reflect.hasField(_attributes, att);
}
public function attributes():Iterator<String> {
if (nodeType != Xml.Element)
throw "bad nodeType";
return Reflect.fields(_attributes).iterator();
}
public function iterator():Iterator<Xml> {
if (_children == null)
throw "bad nodetype";
return untyped _children.iterator();
}
public function elements():Iterator<Xml> {
if (_children == null)
throw "bad nodetype";
return new NativeXmlIterator(_children);
}
public function elementsNamed(name:String):Iterator<Xml> {
if (_children == null)
throw "bad nodetype";
return new NativeXmlNamedIterator(_children, name);
}
public function firstChild():Xml {
if (_children == null)
throw "bad nodetype";
return _children[0];
}
public function firstElement():Xml {
if (_children == null)
throw "bad nodetype";
for (cur in 0..._children.length) {
var n:Xml = _children[cur];
if (n.nodeType == Xml.Element)
return n;
}
return null;
}
public function addChild(x:Xml):Void {
if (_children == null)
throw "bad nodetype";
if (x._parent != null)
x._parent._children.remove(x);
x._parent = this;
_children.push(x);
return;
}
public function removeChild(x:Xml):Bool {
if (_children == null)
throw "bad nodetype";
var b = _children.remove(x);
if (b)
x._parent = null;
return b;
}
public function insertChild(x:Xml, pos:Int):Void {
if (_children == null)
throw "bad nodetype";
if (x._parent != null)
x._parent._children.remove(x);
x._parent = this;
_children.insert(pos, x);
return;
}
public function toString():String {
var s = new StringBuf();
toStringRec(s);
return s.toString();
}
private function toStringRec(s:StringBuf):Void {
switch (nodeType) {
case Xml.Document:
for (x in _children)
x.toStringRec(s);
case Xml.Element:
s.addChar("<".code);
s.add(_nodeName);
for (k in Reflect.fields(_attributes)) {
s.addChar(" ".code);
s.add(k);
s.addChar("=".code);
s.addChar("\"".code);
s.add(Reflect.field(_attributes, k));
s.addChar("\"".code);
}
if (_children.length == 0) {
s.addChar("/".code);
s.addChar(">".code);
return;
}
s.addChar(">".code);
for (x in _children)
x.toStringRec(s);
s.addChar("<".code);
s.addChar("/".code);
s.add(_nodeName);
s.addChar(">".code);
case Xml.PCData:
s.add(StringTools.htmlEscape(_nodeValue));
case Xml.CData:
s.add("<![CDATA[");
s.add(_nodeValue);
s.add("]]>");
case Xml.Comment:
s.add("<!--");
s.add(_nodeValue);
s.add("-->");
case Xml.DocType:
s.add("<!DOCTYPE ");
s.add(_nodeValue);
s.add(">");
case Xml.ProcessingInstruction:
s.add("<?");
s.add(_nodeValue);
s.add("?>");
}
}
}

View File

@ -0,0 +1,386 @@
/*
* 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.
*/
#ifdef EPPC
#include <memory>
#else
#include <memory.h>
#endif
#ifndef HX_WINDOWS
# include <strings.h>
# undef strcmpi
# define strcmpi(a,b) strcasecmp(a,b)
#else
# include <string.h>
#endif
// -------------- parsing --------------------------
enum STATE {
IGNORE_SPACES,
BEGIN,
BEGIN_NODE,
TAG_NAME,
BODY,
ATTRIB_NAME,
EQUALS,
ATTVAL_BEGIN,
ATTRIB_VAL,
CHILDS,
CLOSE,
WAIT_END,
WAIT_END_RET,
PCDATA,
HEADER,
COMMENT,
DOCTYPE,
CDATA,
};
static void xml_error( const char *xml, const char *inWhere, int *line, String msg ) {
String b = HX_CSTRING("Xml parse error : ") + msg + HX_CSTRING(" at line ") + String(*line) + HX_CSTRING(" : ");
String where(inWhere);
int l = where.length;
int nchars = 30;
if( inWhere != xml )
b += HX_CSTRING("...");
if (where.length==0)
b+= HX_CSTRING("<eof>");
else if (where.length<nchars)
b+= where;
else
b+= where.substr(0,nchars) + HX_CSTRING("...");
hx::Throw(b);
}
#define ERRORSTR(msg) xml_error(xml,p,line,msg);
#define ERROR(msg) xml_error(xml,p,line,HX_CSTRING(msg));
static bool is_valid_char( int c ) {
return ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) || ( c >= '0' && c <= '9' ) || c == ':' || c == '.' || c == '_' || c == '-';
}
static void do_parse_xml( const char *xml, const char **lp, int *line, cpp::NativeXmlState callb, String parentname )
{
STATE state = BEGIN;
STATE next = BEGIN;
String aname;
hx::Anon attribs;
String nodename;
const char *start = NULL;
const char *p = *lp;
char c = *p;
int nsubs = 0, nbrackets = 0;
while( c ) {
switch( state ) {
case IGNORE_SPACES:
switch( c ) {
case '\n':
case '\r':
case '\t':
case ' ':
break;
default:
state = next;
continue;
}
break;
case BEGIN:
switch( c ) {
case '<':
state = IGNORE_SPACES;
next = BEGIN_NODE;
break;
default:
start = p;
state = PCDATA;
continue;
}
break;
case PCDATA:
if( c == '<' ) {
callb->pcdata(String(start,p-start).dup());
nsubs++;
state = IGNORE_SPACES;
next = BEGIN_NODE;
}
break;
case CDATA:
if( c == ']' && p[1] == ']' && p[2] == '>' ) {
callb->cdata(String(start,p-start).dup());
nsubs++;
p += 2;
state = BEGIN;
}
break;
case BEGIN_NODE:
switch( c ) {
case '!':
if( p[1] == '[' ) {
p += 2;
if( (p[0] != 'C' && p[0] != 'c') ||
(p[1] != 'D' && p[1] != 'd') ||
(p[2] != 'A' && p[2] != 'a') ||
(p[3] != 'T' && p[3] != 't') ||
(p[4] != 'A' && p[4] != 'a') ||
(p[5] != '[') )
ERROR("Expected <![CDATA[");
p += 5;
state = CDATA;
start = p + 1;
break;
}
if( p[1] == 'D' || p[1] == 'd' ) {
if( (p[2] != 'O' && p[2] != 'o') ||
(p[3] != 'C' && p[3] != 'c') ||
(p[4] != 'T' && p[4] != 't') ||
(p[5] != 'Y' && p[5] != 'y') ||
(p[6] != 'P' && p[6] != 'p') ||
(p[7] != 'E' && p[7] != 'e') )
ERROR("Expected <!DOCTYPE");
p += 7;
state = DOCTYPE;
start = p + 1;
break;
}
if( p[1] != '-' || p[2] != '-' )
ERROR("Expected <!--");
p += 2;
state = COMMENT;
start = p + 1;
break;
case '?':
state = HEADER;
start = p;
break;
case '/':
if( parentname.length==0 )
ERROR("Expected node name");
start = p + 1;
state = IGNORE_SPACES;
next = CLOSE;
break;
default:
state = TAG_NAME;
start = p;
continue;
}
break;
case TAG_NAME:
if( !is_valid_char(c) ) {
if( p == start )
ERROR("Expected node name");
nodename = String(start,p-start).dup();
attribs = hx::Anon_obj::Create();
state = IGNORE_SPACES;
next = BODY;
continue;
}
break;
case BODY:
switch( c ) {
case '/':
state = WAIT_END;
nsubs++;
callb->xml(nodename,attribs);
break;
case '>':
state = CHILDS;
nsubs++;
callb->xml(nodename,attribs);
break;
default:
state = ATTRIB_NAME;
start = p;
continue;
}
break;
case ATTRIB_NAME:
if( !is_valid_char(c) ) {
if( start == p )
ERROR("Expected attribute name");
aname = String(start,p-start).dup();
if( attribs->__Field(aname,hx::paccDynamic) != null() )
ERROR("Duplicate attribute");
state = IGNORE_SPACES;
next = EQUALS;
continue;
}
break;
case EQUALS:
switch( c ) {
case '=':
state = IGNORE_SPACES;
next = ATTVAL_BEGIN;
break;
default:
ERROR("Expected =");
}
break;
case ATTVAL_BEGIN:
switch( c ) {
case '"':
case '\'':
state = ATTRIB_VAL;
start = p;
break;
default:
ERROR("Expected \"");
}
break;
case ATTRIB_VAL:
if( c == *start ) {
attribs->Add( aname, String(start+1,p-start-1).dup() );
state = IGNORE_SPACES;
next = BODY;
}
break;
case CHILDS:
*lp = p;
do_parse_xml(xml,lp,line,callb,nodename);
p = *lp;
start = p;
state = BEGIN;
break;
case WAIT_END:
switch( c ) {
case '>':
callb->done();
state = BEGIN;
break;
default :
ERROR("Expected >");
}
break;
case WAIT_END_RET:
switch( c ) {
case '>':
if( nsubs == 0 )
callb->pcdata(HX_CSTRING(""));
*lp = p;
return;
default :
ERROR("Expected >");
}
break;
case CLOSE:
if( !is_valid_char(c) ) {
if( start == p )
ERROR("Expected node name");
{
String v = String(start,p - start).dup();
if( strcmpi(parentname.__s,v.__s) != 0 ) {
ERRORSTR(HX_CSTRING("Expected </") + parentname + HX_CSTRING(">"));
}
}
state = IGNORE_SPACES;
next = WAIT_END_RET;
continue;
}
break;
case COMMENT:
if( c == '-' && p[1] == '-' && p[2] == '>' ) {
callb->comment(String(start,p-start).dup());
p += 2;
state = BEGIN;
}
break;
case DOCTYPE:
if( c == '[' )
nbrackets++;
else if( c == ']' )
nbrackets--;
else if( c == '>' && nbrackets == 0 ) {
callb->doctype(String(start,p-start).dup());
state = BEGIN;
}
break;
case HEADER:
if( c == '?' && p[1] == '>' ) {
p++;
callb->comment(String(start,p-start).dup());
state = BEGIN;
}
break;
}
c = *++p;
if( c == '\n' )
(*line)++;
}
if( state == BEGIN ) {
start = p;
state = PCDATA;
}
if( parentname.__s == 0 && state == PCDATA ) {
if( p != start || nsubs == 0 )
callb->pcdata(String(start,p-start).dup());
return;
}
ERROR("Unexpected end");
}
// ----------------------------------------------
/**
<doc>
<h1>Xml</h1>
<p>
The standard event-driven XML parser.
</p>
</doc>
**/
/**
parse_xml : xml:string -> events:object -> void
<doc>
The [parse_xml] parse a string and for each parsed element call the
corresponding object method in [events] :
<ul>
<li>[void xml( name : string, attribs : object)] when an XML node is found</li>
<li>[void done()] when an XML node is closed</li>
<li>[void pcdata(string)] when PCData chars found</li>
<li>[void cdata(string)] when a CData session is found</li>
<li>[void comment(string)] when some comment or special header is found</li>
</ul>
You can then implement the events so they build the appropriate XML data
structure needed by your language.
</doc>
**/
static void parse_xml( String str, cpp::NativeXmlState state )
{
int line = 0;
const char *p = str.__s;
// skip BOM
if( p[0] == (char)0xEF && p[1] == (char)0xBB && p[2] == (char)0xBF )
p += 3;
do_parse_xml(p,&p,&line,state,String());
}

View File

@ -0,0 +1,26 @@
/*
* 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 cpp;
@:noPackageRestrict
typedef Object = Dynamic;

View File

@ -0,0 +1,39 @@
/*
* 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 cpp;
extern class ObjectType {
inline static var vtUnknown = -1;
inline static var vtInt = 0xff;
inline static var vtNull = 0;
inline static var vtFloat = 1;
inline static var vtBool = 2;
inline static var vtString = 3;
inline static var vtObject = 4;
inline static var vtArray = 5;
inline static var vtFunction = 6;
inline static var vtEnum = 7;
inline static var vtClass = 8;
inline static var vtInt64 = 9;
inline static var vtAbstractBase = 0x100;
}

View File

@ -0,0 +1,86 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package cpp;
import haxe.extern.AsVar;
@:coreType
@:semantics(variable)
extern class Pointer<T> extends ConstPointer<T> implements ArrayAccess<T> {
var ref(get, set):Reference<T>;
function get_ref():Reference<T>;
function set_ref(t:T):Reference<T>;
function setAt(inIndex:Int, value:T):Void;
static function fromRaw<T>(ptr:RawPointer<T>):Pointer<T>;
@:native("::cpp::Pointer_obj::fromRaw")
static function fromStar<T>(star:Star<T>):Pointer<T>;
@:native("::cpp::Pointer_obj::fromHandle")
static function nativeFromHandle<T>(inHandle:Dynamic, ?inKind:String):AutoCast;
inline static function fromHandle<T>(inHandle:Dynamic, ?inKind:String):Pointer<T> {
return cast nativeFromHandle(inHandle, inKind);
}
static function fromPointer<T>(inNativePointer:Dynamic):Pointer<T>;
static function addressOf<T>(inVariable:cpp.Reference<T>):Pointer<T>;
static function endOf<T:{}>(inVariable:T):Pointer<cpp.Void>;
@:native("::cpp::Pointer_obj::arrayElem")
static function nativeArrayElem<T>(array:Array<T>, inElem:Int):AutoCast;
inline static function arrayElem<T>(array:Array<T>, inElem:Int):Pointer<T> {
return cast nativeArrayElem(array, inElem);
}
@:native("::cpp::Pointer_obj::ofArray")
static function nativeOfArray<T>(array:Array<T>):AutoCast;
inline static function ofArray<T>(array:Array<T>):Pointer<T> {
return cast nativeOfArray(array);
}
inline function toUnmanagedArray(elementCount:Int):Array<T> {
var result = new Array<T>();
NativeArray.setUnmanagedData(result, this, elementCount);
return result;
}
inline function toUnmanagedVector(elementCount:Int):haxe.ds.Vector<T>
return cast toUnmanagedArray(elementCount);
override function inc():Pointer<T>;
override function dec():Pointer<T>;
override function incBy(inT:Int):Pointer<T>;
override function decBy(inT:Int):Pointer<T>;
override function add(inT:Int):Pointer<T>;
override function sub(inT:Int):Pointer<T>;
function postIncRef():Reference<T>;
function destroy():Void;
function destroyArray():Void;
}

View File

@ -0,0 +1,117 @@
/*
* 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 cpp;
#if macro
import haxe.macro.Context;
import haxe.macro.Type;
import haxe.macro.Expr;
#end
@:noPackageRestrict
class Prime {
#if (!macro && cpp)
public static function _loadPrime(lib:String, prim:String, signature:String, quietFail = false):Dynamic {
var factory:Callable<ConstCharStar->Object> = untyped __global__.__hxcpp_cast_get_proc_address(lib, prim + "__prime", quietFail);
if (factory != null) {
var func:Dynamic = factory.call(signature);
if (func == null && !quietFail)
throw '$prim does not have signature $signature';
return func;
}
return null;
}
#end
#if (macro)
static function codeToType(code:String, forCpp:Bool):String {
if (code == "c" && !forCpp)
throw "const char * type only supported in cpp mode";
switch (code) {
case "b":
return "Bool";
case "i":
return "Int";
case "d":
return "Float";
case "s":
return "String";
case "f":
return forCpp ? "cpp.Float32" : "Float";
case "o":
return forCpp ? "cpp.Object" : "Dynamic";
case "v":
return forCpp ? "cpp.Void" : "Dynamic";
case "c":
return "cpp.ConstCharStar";
default:
throw "Unknown signature type :" + code;
}
}
#end
public static function nekoInit(inModuleName:String):Bool {
#if neko
var init = neko.Lib.load(inModuleName, "neko_init", 5);
if (init != null) {
init(function(s) return new String(s), function(len:Int) {
var r = [];
if (len > 0)
r[len - 1] = null;
return r;
}, null, true, false);
return true;
}
#end
return false;
}
public static macro function load(inModule:String, inName:String, inSig:String, inAllowFail:Bool = false) {
var parts = inSig.split("");
if (parts.length < 1)
throw "Invalid function signature " + inSig;
var argCount = parts.length - 1;
var cppiaMode = Context.defined("cppia");
var cppMode = Context.defined("cpp") && !cppiaMode;
var typeString = parts.length == 1 ? "Void" : codeToType(parts.shift(), cppMode);
for (p in parts)
typeString += "->" + codeToType(p, cppMode);
if (cppMode) {
typeString = "cpp.Callable<" + typeString + ">";
var expr = 'new $typeString(cpp.Prime._loadPrime("$inModule","$inName","$inSig",$inAllowFail))';
return Context.parse(expr, Context.currentPos());
} else {
if (argCount > 5)
argCount = -1;
var lazy = inAllowFail ? "loadLazy" : "load";
var lib = cppiaMode ? "cpp" : "neko";
var expr = 'new cpp.Callable<$typeString>($lib.Lib.$lazy("$inModule","$inName",$argCount))';
return Context.parse(expr, Context.currentPos());
}
}
}

View File

@ -0,0 +1,43 @@
/*
* 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 cpp;
class Random {
var r:Dynamic;
public function new() {
r = cpp.NativeRandom.random_new();
}
public function setSeed(s:Int) {
cpp.NativeRandom.random_set_seed(r, s);
}
public function int(max:Int):Int {
return cpp.NativeRandom.random_int(r, max);
}
public function float():Float {
return cpp.NativeRandom.random_float(r);
}
}

View File

@ -0,0 +1,29 @@
/*
* 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 cpp;
@:unreflective
extern class RawConstPointer<T> implements ArrayAccess<T> {
@:native("::hx::AddressOf")
static function addressOf<T>(t:T):RawConstPointer<T>;
}

View File

@ -0,0 +1,29 @@
/*
* 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 cpp;
@:unreflective
extern class RawPointer<T> extends RawConstPointer<T> {
@:native("::hx::AddressOf")
static function addressOf<T>(t:T):RawPointer<T>;
}

View File

@ -0,0 +1,30 @@
/*
* 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 cpp;
/**
Allows haxe to type result correctly, and hxcpp can recognise this and
prevent unwanted casting.
**/
@:semantics(reference)
typedef Reference<T> = T;

View File

@ -0,0 +1,25 @@
/*
* 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 cpp;
abstract Rest<T>(Array<T>) {}

View File

@ -0,0 +1,27 @@
/*
* 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 cpp;
@:native("size_t")
@:scalar @:coreType @:notNull
extern abstract SizeT from(Int) to(Int) {}

View File

@ -0,0 +1,29 @@
/*
* 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 cpp;
/**
Allows haxe to type result correctly, and hxcpp can recognise this use the
correct type.
**/
typedef Star<T> = Null<T>;

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 cpp;
using cpp.NativeString;
@:native("::hx::StdString")
@:include("hx/StdString.h")
@:stackOnly
@:structAccess
@:unreflective
extern class StdString {
@:native("std::string::npos")
static var npos(default, null):Int;
// function new(inData:StdStringData);
@:native("::hx::StdString")
static function ofString(s:String):StdString;
// function toString():String;
// function find(s:String):Int;
// function substr(pos:Int, len:Int):StdString;
function c_str():ConstPointer<Char>;
function size():Int;
function find(s:String):Int;
function substr(pos:Int, len:Int):StdString;
function toString():String;
function toStdString():StdString;
}

View File

@ -0,0 +1,37 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package cpp;
using cpp.NativeString;
@:native("::hx::StdString const &")
@:include("hx/StdString.h")
@:structAccess
extern class StdStringRef {
function c_str():ConstPointer<Char>;
function size():Int;
function find(s:String):Int;
function substr(pos:Int, len:Int):StdString;
function toString():String;
function toStdString():StdString;
}

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 cpp;
@:include("stdio.h")
extern class Stdio {
@:native("printf")
static function printf(format:ConstCharStar, rest:Rest<VarArg>):Void;
@:native("fopen")
static function fopen(filename:ConstCharStar, mode:ConstCharStar):FILE;
@:native("fwrite")
static function fwrite<T>(data:RawPointer<T>, elemSize:SizeT, elemCount:SizeT, file:FILE):SizeT;
@:native("fclose")
static function fclose(file:FILE):Int;
@:native("fprintf")
static function fprintf(file:FILE, format:ConstCharStar, rest:Rest<VarArg>):Void;
}

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 cpp;
@:include("stdlib.h")
extern class Stdlib {
@:native("malloc")
static function nativeMalloc(bytes:Int):cpp.RawPointer<cpp.Void>;
@:native("calloc")
static function nativeCalloc(bytes:Int):cpp.RawPointer<cpp.Void>;
@:native("realloc")
static function nativeRealloc(inPtr:cpp.RawPointer<cpp.Void>, bytes:Int):cpp.RawPointer<cpp.Void>;
@:native("free")
static function nativeFree(ptr:cpp.RawPointer<cpp.Void>):Void;
@:native("memcpy")
static function nativeMemcpy(dest:cpp.RawPointer<cpp.Void>, src:cpp.RawConstPointer<cpp.Void>, bytes:Int):Void;
@:native("::hx::ClassSizeOf") @:templatedCall
static function sizeof<T>(t:T):Int;
inline static function memcpy<DEST, SRC>(dest:cpp.Pointer<DEST>, src:cpp.ConstPointer<SRC>, bytes:Int):Void
nativeMemcpy(cast dest.ptr, cast src.ptr, bytes);
inline static function malloc<T>(bytes:Int):cpp.Pointer<T>
return cast nativeMalloc(bytes);
inline static function calloc<T>(bytes:Int):cpp.Pointer<T>
return cast nativeCalloc(bytes);
inline static function realloc<T>(ioPtr:cpp.Pointer<T>, bytes:Int):Void
ioPtr.setRaw(nativeRealloc(cast ioPtr.ptr, bytes));
inline static function free<T>(ptr:cpp.Pointer<T>):Void {
if (ptr != null) {
nativeFree(cast ptr.ptr);
ptr.ptr = null;
}
}
}

View File

@ -0,0 +1,28 @@
/*
* 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 cpp;
/**
Wraps external types with a class that integrates with Dynamic.
**/
typedef Struct<T> = T;

View File

@ -0,0 +1,25 @@
/*
* 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 cpp;
@:coreType @:notNull @:runtimeValue abstract UInt16 from Int to Int {}

View File

@ -0,0 +1,25 @@
/*
* 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 cpp;
@:coreType @:notNull @:runtimeValue abstract UInt32 from Int to Int {}

View File

@ -0,0 +1,25 @@
/*
* 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 cpp;
@:coreType @:notNull @:runtimeValue abstract UInt64 from Int to Int {}

View File

@ -0,0 +1,25 @@
/*
* 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 cpp;
@:coreType @:notNull @:runtimeValue abstract UInt8 from Int to Int {}

View File

@ -0,0 +1,29 @@
/*
* 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 cpp;
/**
Allows haxe to type params correctly, and hxcpp can recognise this use the
correct type.
**/
typedef VarArg = Dynamic;

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 cpp;
@:native("cpp::VirtualArray")
@:coreType extern class NativeVirtualArray implements ArrayAccess<Dynamic> {
function new():Void;
var length(get, null):Int;
// concat<T>( a:Array<T> ) : Array<T> ?
function concat(a:VirtualArray):VirtualArray;
function join(sep:String):String;
function pop():Dynamic;
function push(x:Dynamic):Int;
function reverse():Void;
function shift():Dynamic;
function slice(pos:Int, ?end:Int):VirtualArray;
function sort(f:Dynamic->Dynamic->Int):Void;
function splice(pos:Int, len:Int):VirtualArray;
function toString():String;
function unshift(x:Dynamic):Void;
function insert(pos:Int, x:Dynamic):Void;
function remove(x:Dynamic):Bool;
function indexOf(x:Dynamic, ?fromIndex:Int):Int;
function lastIndexOf(x:Dynamic, ?fromIndex:Int):Int;
function copy():VirtualArray;
function iterator():Iterator<Dynamic>;
function keyValueIterator():KeyValueIterator<Int, Dynamic>;
function map<S>(f:Dynamic->S):VirtualArray;
function filter(f:Dynamic->Bool):VirtualArray;
function resize(len:Int):Void;
}
abstract VirtualArray(NativeVirtualArray) {
// Add these two functions...
@:from extern inline static public function fromArray<T>(a:Array<T>):VirtualArray
return untyped a;
@:to extern inline public function toArray<T>():Array<T>
return untyped this;
// The rest is just boiler-plate
inline public function new()
this = new NativeVirtualArray();
@:arrayAccess extern inline function get(idx:Int):Dynamic
return untyped this[idx];
@:arrayAccess extern inline function set<T>(pos:Int, value:T):T
return untyped this[idx] = value;
public var length(get, never):Int;
extern inline public function get_length():Int
return this.length;
// concat<T>( a:Array<T> ) : Array<T> ?
extern inline public function concat(a:VirtualArray):VirtualArray
return this.concat(a);
extern inline public function join(sep:String):String
return this.join(sep);
extern inline public function pop():Dynamic
return this.pop();
extern inline public function push(x:Dynamic):Int
return this.push(x);
extern inline public function reverse():Void
this.reverse();
extern inline public function shift():Dynamic
return this.shift();
extern inline public function slice(pos:Int, ?end:Int):VirtualArray
return this.slice(pos, end);
extern inline public function sort(f:Dynamic->Dynamic->Int):Void
this.sort(f);
extern inline public function splice(pos:Int, len:Int):VirtualArray
return this.slice(pos, len);
extern inline public function unshift(x:Dynamic):Void
this.unshift(x);
extern inline public function insert(pos:Int, x:Dynamic):Void
this.insert(pos, x);
extern inline public function remove(x:Dynamic):Bool
return this.remove(x);
extern inline public function indexOf(x:Dynamic, ?fromIndex:Int):Int
return this.indexOf(x, fromIndex);
extern inline public function lastIndexOf(x:Dynamic, ?fromIndex:Int):Int
return this.lastIndexOf(x, fromIndex);
extern inline public function copy():VirtualArray
return this.copy();
extern inline public function iterator():Iterator<Dynamic>
return this.iterator();
extern inline public function keyValueIterator():KeyValueIterator<Int, Dynamic>
return this.keyValueIterator();
extern inline public function map<S>(f:Dynamic->S):VirtualArray
return this.map(f);
extern inline public function filter(f:Dynamic->Bool):VirtualArray
return this.filter(f);
extern inline public function resize(len:Int):Void
return this.resize(len);
}

View File

@ -0,0 +1,26 @@
/*
* 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 cpp;
@:native("void")
extern class Void {}

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
}
}

Some files were not shown because too many files have changed in this diff Show More