This commit is contained in:
Dante
2026-05-21 23:40:20 -07:00
parent 3e2915dff7
commit 877a69d844
5737 changed files with 29796 additions and 1589684 deletions

View File

@ -52,7 +52,7 @@ class EReg {
}
}
ropt |= FLAGS.UTF8; // always check validity of utf8 string
ropt |= FLAGS.UTF; // always check validity of utf8 string
ropt |= FLAGS.UCP; // always enable utf8 character properties
if (global == null)
@ -208,7 +208,7 @@ class EReg {
static function __init__():Void {
if (Rex == null) {
throw "Rex is missing. Please install lrexlib-pcre.";
throw "Rex is missing. Please install lrexlib-pcre2.";
}
}
}

View File

@ -26,10 +26,12 @@ import lua.Boot;
@:coreApi class Reflect {
public inline static function hasField(o:Dynamic, field:String):Bool {
if (Lua.type(o) == "string" && (untyped String.prototype[field] != null || field == "length")) {
return true;
return if (inline isFunction(o)) {
false;
} else if (Lua.type(o) == "string" && (untyped String.prototype[field] != null || field == "length")) {
true;
} else
return untyped o.__fields__ != null ? o.__fields__[field] != null : o[field] != null;
untyped o.__fields__ != null ? o.__fields__[field] != null : o[field] != null;
}
public static function field(o:Dynamic, field:String):Dynamic
@ -116,7 +118,7 @@ import lua.Boot;
untyped {
if (v == null)
return false;
var t = __lua__("type(v)");
var t = lua.Lua.type(v);
return (t == "string" || (t == "table" && v.__enum__ == null))
|| (t == "function" && (lua.Boot.isClass(v) || lua.Boot.isEnum(v)) != null);
}

View File

@ -58,28 +58,24 @@ import lua.NativeStringTools;
public static function parseInt(x:String):Null<Int> {
if (x == null)
return null;
var hexMatch = NativeStringTools.match(x, "^[ \t\r\n]*([%-+]*0[xX][%da-fA-F]*)");
if (hexMatch != null) {
var sign = switch StringTools.fastCodeAt(hexMatch, 0) {
case '-'.code: -1;
case '+'.code: 1;
case _: 0;
}
return (sign == -1 ? -1 : 1) * lua.Lua.tonumber(hexMatch.substr(sign == 0 ? 2 : 3), 16);
} else {
var intMatch = NativeStringTools.match(x, "^ *[%-+]?%d*");
if (intMatch != null) {
return lua.Lua.tonumber(intMatch);
} else {
return null;
}
untyped {
__lua__("local sign, numString = {0}", NativeStringTools.match(x, "^%s*([%-+]?)0[xX]([%da-fA-F]*)"));
if (numString != null)
return switch sign {
case '-': -lua.Lua.tonumber(numString, 16);
case _: lua.Lua.tonumber(numString, 16);
}
}
final intMatch = NativeStringTools.match(x, "^%s*[%-+]?%d*");
if (intMatch == null)
return null;
return lua.Lua.tonumber(intMatch);
}
public static function parseFloat(x:String):Float {
if (x == null || x == "")
return Math.NaN;
var digitMatch = NativeStringTools.match(x, "^ *[%.%-+]?[0-9]%d*");
var digitMatch = NativeStringTools.match(x, "^%s*[%.%-+]?[0-9]%d*");
if (digitMatch == null) {
return Math.NaN;
}

View File

@ -62,7 +62,7 @@ class String {
public inline function toLowerCase():String
return BaseString.lower(this);
public inline function indexOf(str:String, ?startIndex:Int):Int {
public function indexOf(str:String, ?startIndex:Int):Int {
if (startIndex == null)
startIndex = 1;
else
@ -86,7 +86,7 @@ class String {
return startIndex > length ? length : startIndex;
}
public inline function lastIndexOf(str:String, ?startIndex:Int):Int {
public function lastIndexOf(str:String, ?startIndex:Int):Int {
var ret = -1;
if (startIndex == null)
startIndex = length;
@ -99,11 +99,11 @@ class String {
return ret;
}
public inline function split(delimiter:String):Array<String> {
var idx = 1;
public function split(delimiter:String):Array<String> {
var idx:Null<Int> = 1;
var ret = [];
while (idx != null) {
var newidx = 0;
var newidx:Null<Int> = 0;
if (delimiter.length > 0) {
newidx = BaseString.find(this, delimiter, idx, true).begin;
} else if (idx >= this.length) {
@ -128,7 +128,7 @@ class String {
return this;
}
public inline function substring(startIndex:Int, ?endIndex:Int):String {
public function substring(startIndex:Int, ?endIndex:Int):String {
if (endIndex == null)
endIndex = this.length;
if (endIndex < 0)
@ -151,7 +151,7 @@ class String {
return BaseString.byte(this, index + 1);
}
public inline function substr(pos:Int, ?len:Int):String {
public function substr(pos:Int, ?len:Int):String {
if (len == null || len > pos + this.length)
len = this.length;
else if (len < 0)

View File

@ -89,7 +89,7 @@ class Sys {
}
public inline static function getCwd():String
return Misc.cwd();
return haxe.io.Path.addTrailingSlash(Misc.cwd());
public inline static function setCwd(s:String):Void
Misc.chdir(s);
@ -98,7 +98,9 @@ class Sys {
return Os.getenv(s);
}
public inline static function putEnv(s:String, v:String):Void {
public inline static function putEnv(s:String, v:Null<String>):Void {
if (v == null)
return Os.unsetenv(s);
Os.setenv(s, v);
}

View File

@ -49,6 +49,7 @@ class Exception {
return __nativeException;
}
@:keep // required for uncaught error handling
public function toString():String {
return message;
}

View File

@ -96,7 +96,7 @@ class IntMap<T> implements haxe.Constraints.IMap<Int, T> {
public function toString():String {
var s = new StringBuf();
s.add("{");
s.add("[");
var it = keys();
for (i in it) {
s.add(i);
@ -105,7 +105,7 @@ class IntMap<T> implements haxe.Constraints.IMap<Int, T> {
if (it.hasNext())
s.add(", ");
}
s.add("}");
s.add("]");
return s.toString();
}

View File

@ -100,7 +100,7 @@ class ObjectMap<A, B> implements haxe.Constraints.IMap<A, B> {
public function toString():String {
var s = new StringBuf();
s.add("{");
s.add("[");
var it = keys();
for (i in it) {
s.add(i);
@ -109,7 +109,7 @@ class ObjectMap<A, B> implements haxe.Constraints.IMap<A, B> {
if (it.hasNext())
s.add(", ");
}
s.add("}");
s.add("]");
return s.toString();
}

View File

@ -46,7 +46,7 @@ class StringMap<T> implements haxe.Constraints.IMap<String, T> {
untyped {
var ret = h[key];
if (ret == tnull) {
ret = null;
return null;
}
return ret;
}
@ -100,7 +100,7 @@ class StringMap<T> implements haxe.Constraints.IMap<String, T> {
public function toString():String {
var s = new StringBuf();
s.add("{");
s.add("[");
var it = keys();
for (i in it) {
s.add(i);
@ -109,7 +109,7 @@ class StringMap<T> implements haxe.Constraints.IMap<String, T> {
if (it.hasNext())
s.add(", ");
}
s.add("}");
s.add("]");
return s.toString();
}

View File

@ -42,7 +42,11 @@ class JsonParser {
If `str` is null, the result is unspecified.
**/
static public inline function parse(str:String):Dynamic {
#if lua_vanilla
return new JsonParser(str).doParse();
#else
return lua.lib.hxluasimdjson.Json.parse(str);
#end
}
var str:String;

View File

@ -159,76 +159,4 @@ class Socket {
var write_arr = res.write == null ? [] : Table.toArray(res.write).map(convert_socket);
return {read: read_arr, write: write_arr, others: []};
}
}
private class SocketInput extends haxe.io.Input {
var tcp:TcpClient;
public function new(tcp:TcpClient) {
this.tcp = tcp;
}
override public function readByte():Int {
var res = tcp.receive(1);
if (res.message == "closed"){
throw new haxe.io.Eof();
}
else if (res.message != null)
throw 'Error : ${res.message}';
return res.result.charCodeAt(0);
}
override public function readBytes(s:Bytes, pos:Int, len:Int):Int {
var leftToRead = len;
var b = s.getData();
if (pos < 0 || len < 0 || pos + len > s.length)
throw haxe.io.Error.OutsideBounds;
var readCount = 0;
try {
while (leftToRead > 0) {
b[pos] = cast readByte();
pos++;
readCount++;
leftToRead--;
}
} catch (e:haxe.io.Eof) {
if (readCount == 0) {
throw e;
}
}
return readCount;
}
}
private class SocketOutput extends haxe.io.Output {
var tcp:TcpClient;
public function new(tcp:TcpClient) {
this.tcp = tcp;
}
override public function writeByte(c:Int):Void {
var char = NativeStringTools.char(c);
var res = tcp.send(char);
if (res.message != null){
throw 'Error : Socket writeByte : ${res.message}';
}
}
override public function writeBytes(s:Bytes, pos:Int, len:Int):Int {
if (pos < 0 || len < 0 || pos + len > s.length)
throw Error.OutsideBounds;
var b = s.getData().slice(pos, pos +len).map(function(byte){
return lua.NativeStringTools.char(byte);
});
var encoded = Table.concat(cast b, 0);
var res = tcp.send(encoded);
if (res.message != null){
throw 'Error : Socket writeByte : ${res.message}';
}
return len;
}
}
}

View File

@ -0,0 +1,69 @@
/*
* Copyright (C)2005-2022 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.net;
import lua.lib.luasocket.socket.TcpClient;
import lua.*;
import haxe.io.Bytes;
import haxe.io.Error;
class SocketInput extends haxe.io.Input {
var tcp:TcpClient;
public function new(tcp:TcpClient) {
this.tcp = tcp;
}
override public function readByte():Int {
var res = tcp.receive(1);
if (res.message == "closed"){
throw new haxe.io.Eof();
}
else if (res.message != null)
throw 'Error : ${res.message}';
return res.result.charCodeAt(0);
}
override public function readBytes(s:Bytes, pos:Int, len:Int):Int {
var leftToRead = len;
var b = s.getData();
if (pos < 0 || len < 0 || pos + len > s.length)
throw haxe.io.Error.OutsideBounds;
var readCount = 0;
try {
while (leftToRead > 0) {
b[pos] = cast readByte();
pos++;
readCount++;
leftToRead--;
}
} catch (e:haxe.io.Eof) {
if (readCount == 0) {
throw e;
}
}
return readCount;
}
}

View File

@ -0,0 +1,61 @@
/*
* Copyright (C)2005-2022 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.net;
import lua.lib.luasocket.socket.TcpClient;
import lua.*;
import haxe.io.Bytes;
import haxe.io.Error;
class SocketOutput extends haxe.io.Output {
var tcp:TcpClient;
public function new(tcp:TcpClient) {
this.tcp = tcp;
}
override public function writeByte(c:Int):Void {
var char = NativeStringTools.char(c);
var res = tcp.send(char);
if (res.message != null){
throw 'Error : Socket writeByte : ${res.message}';
}
}
override public function writeBytes(s:Bytes, pos:Int, len:Int):Int {
if (pos < 0 || len < 0 || pos + len > s.length)
throw Error.OutsideBounds;
var b = s.getData().slice(pos, pos +len).map(function(byte){
return lua.NativeStringTools.char(byte);
});
var encoded = Table.concat(cast b, 0);
var res = tcp.send(encoded);
if (res.message != null){
throw 'Error : Socket writeByte : ${res.message}';
}
return len;
}
}

View File

@ -0,0 +1,69 @@
/*
* Copyright (C)2005-2022 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.ssl;
import sys.net.Host;
import sys.net.SocketInput;
import sys.net.SocketOutput;
import lua.lib.luasocket.Socket as LuaSocket;
import lua.lib.luasec.Ssl as LuaSecSsl;
import lua.lib.luasec.SslTcpClient;
import haxe.io.Bytes;
import haxe.io.Error;
class Socket extends sys.net.Socket {
var _sslSocket:SslTcpClient;
private function wrap(sock:LuaSocket):SslTcpClient {
var res = LuaSecSsl.wrap(sock, {mode: Client, protocol: Any});
if (res.message != null) {
throw 'Socket Error : ${res.message}';
}
return res.result;
}
public function handshake():Void {
var res = this._sslSocket.dohandshake();
if (res.message != null) {
throw 'Handshake Error : ${res.message}';
}
}
public override function connect(host:Host, port:Int):Void {
var res = LuaSocket.connect(host.host, port);
if (res.message != null)
throw 'Socket Error : ${res.message}';
var sslSock = this.wrap(res.result);
input = new SocketInput(sslSock);
output = new SocketOutput(sslSock);
_sslSocket = sslSock;
_sslSocket.settimeout(timeout);
this.handshake();
}
public override function close():Void {
_sslSocket.close();
}
}