forked from LeenkxTeam/LNXSDK
Update
This commit is contained in:
@ -29,6 +29,7 @@ import sys.io.FileInput;
|
||||
extern class FileHandle extends UserData {
|
||||
function flush():Void;
|
||||
function read(arg:Rest<EitherType<String, Int>>):String;
|
||||
function lines():NativeIterator<String>;
|
||||
function close():Void;
|
||||
|
||||
function write(str:String):Void;
|
||||
|
||||
@ -33,8 +33,8 @@ local function _hx_new(prototype)
|
||||
end
|
||||
|
||||
function _hx_field_arr(obj)
|
||||
res = {}
|
||||
idx = 0
|
||||
local res = {}
|
||||
local idx = 0
|
||||
if obj.__fields__ ~= nil then
|
||||
obj = obj.__fields__
|
||||
end
|
||||
|
||||
@ -1,16 +1,21 @@
|
||||
-- require this for lua 5.1
|
||||
pcall(require, 'bit')
|
||||
if bit then
|
||||
_hx_bit_raw = bit
|
||||
_hx_bit = setmetatable({}, { __index = _hx_bit_raw });
|
||||
else
|
||||
_hx_bit_raw = _G.require('bit32')
|
||||
_hx_bit = setmetatable({}, { __index = _hx_bit_raw });
|
||||
local hasBit32, bit32 = pcall(require, 'bit32')
|
||||
if hasBit32 then --if we are on Lua 5.1, bit32 will be the default.
|
||||
_hx_bit_raw = bit32
|
||||
_hx_bit = setmetatable({}, { __index = _hx_bit_raw })
|
||||
-- lua 5.2 weirdness
|
||||
_hx_bit.bnot = function(...) return _hx_bit_clamp(_hx_bit_raw.bnot(...)) end;
|
||||
_hx_bit.bxor = function(...) return _hx_bit_clamp(_hx_bit_raw.bxor(...)) end;
|
||||
_hx_bit.bnot = function(...) return _hx_bit_clamp(_hx_bit_raw.bnot(...)) end
|
||||
_hx_bit.bxor = function(...) return _hx_bit_clamp(_hx_bit_raw.bxor(...)) end
|
||||
else
|
||||
--If we do not have bit32, fallback to 'bit'
|
||||
local hasBit, bit = pcall(require, 'bit')
|
||||
if not hasBit then
|
||||
error("Failed to load bit or bit32")
|
||||
end
|
||||
_hx_bit_raw = bit
|
||||
_hx_bit = setmetatable({}, { __index = _hx_bit_raw })
|
||||
end
|
||||
|
||||
-- see https://github.com/HaxeFoundation/haxe/issues/8849
|
||||
_hx_bit.bor = function(...) return _hx_bit_clamp(_hx_bit_raw.bor(...)) end;
|
||||
_hx_bit.band = function(...) return _hx_bit_clamp(_hx_bit_raw.band(...)) end;
|
||||
_hx_bit.arshift = function(...) return _hx_bit_clamp(_hx_bit_raw.arshift(...)) end;
|
||||
_hx_bit.bor = function(...) return _hx_bit_clamp(_hx_bit_raw.bor(...)) end
|
||||
_hx_bit.band = function(...) return _hx_bit_clamp(_hx_bit_raw.band(...)) end
|
||||
_hx_bit.arshift = function(...) return _hx_bit_clamp(_hx_bit_raw.arshift(...)) end
|
||||
|
||||
8
Kha/Tools/windows_x64/std/lua/_lua/_hx_handle_error.lua
Normal file
8
Kha/Tools/windows_x64/std/lua/_lua/_hx_handle_error.lua
Normal file
@ -0,0 +1,8 @@
|
||||
function _hx_handle_error(obj)
|
||||
local message = tostring(obj)
|
||||
if _G.debug and _G.debug.traceback then
|
||||
-- level 2 to skip _hx_handle_error
|
||||
message = _G.debug.traceback(message, 2)
|
||||
end
|
||||
return setmetatable({}, { __tostring = function() return message end })
|
||||
end
|
||||
8
Kha/Tools/windows_x64/std/lua/_lua/_hx_luv.lua
Normal file
8
Kha/Tools/windows_x64/std/lua/_lua/_hx_luv.lua
Normal file
@ -0,0 +1,8 @@
|
||||
if package.loaded.luv then
|
||||
_hx_luv = _G.require("luv");
|
||||
else
|
||||
_hx_luv = {
|
||||
run=function(mode) return false end,
|
||||
loop_alive=function() return false end
|
||||
}
|
||||
end
|
||||
@ -99,16 +99,3 @@ function _hx_tostring(obj, depth)
|
||||
return ""
|
||||
end
|
||||
end
|
||||
|
||||
function _hx_error(obj)
|
||||
if obj.value then
|
||||
_G.print("runtime error:\n " .. _hx_tostring(obj.value));
|
||||
else
|
||||
_G.print("runtime error:\n " .. tostring(obj));
|
||||
end
|
||||
|
||||
if _G.debug and _G.debug.traceback then
|
||||
_G.print(debug.traceback());
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -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.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -49,6 +49,7 @@ class Exception {
|
||||
return __nativeException;
|
||||
}
|
||||
|
||||
@:keep // required for uncaught error handling
|
||||
public function toString():String {
|
||||
return message;
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
69
Kha/Tools/windows_x64/std/lua/_std/sys/net/SocketInput.hx
Normal file
69
Kha/Tools/windows_x64/std/lua/_std/sys/net/SocketInput.hx
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
61
Kha/Tools/windows_x64/std/lua/_std/sys/net/SocketOutput.hx
Normal file
61
Kha/Tools/windows_x64/std/lua/_std/sys/net/SocketOutput.hx
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
69
Kha/Tools/windows_x64/std/lua/_std/sys/ssl/Socket.hx
Normal file
69
Kha/Tools/windows_x64/std/lua/_std/sys/ssl/Socket.hx
Normal 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();
|
||||
}
|
||||
}
|
||||
@ -24,7 +24,7 @@ package lua.lib.lrexlib;
|
||||
|
||||
import haxe.extern.EitherType;
|
||||
|
||||
@:luaRequire("rex_pcre")
|
||||
@:luaRequire("rex_pcre2")
|
||||
extern class Rex {
|
||||
inline static function create(expr:String, flag:EitherType<Int, String>):Rex {
|
||||
return untyped Rex['new'](expr, flag);
|
||||
|
||||
44
Kha/Tools/windows_x64/std/lua/lib/luasec/Ssl.hx
Normal file
44
Kha/Tools/windows_x64/std/lua/lib/luasec/Ssl.hx
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 lua.lib.luasec;
|
||||
|
||||
import lua.lib.luasocket.Socket as LuaSocket;
|
||||
|
||||
@:luaRequire("ssl")
|
||||
extern class Ssl {
|
||||
static function wrap(sock:LuaSocket, params: SslParams):Result<SslTcpClient>;
|
||||
}
|
||||
|
||||
typedef SslParams = {
|
||||
mode: Mode,
|
||||
protocol: Protocol,
|
||||
}
|
||||
|
||||
enum abstract Mode(String) {
|
||||
var Client = "client";
|
||||
var Server = "server";
|
||||
}
|
||||
|
||||
enum abstract Protocol(String) {
|
||||
var Any = "any";
|
||||
}
|
||||
29
Kha/Tools/windows_x64/std/lua/lib/luasec/SslTcpClient.hx
Normal file
29
Kha/Tools/windows_x64/std/lua/lib/luasec/SslTcpClient.hx
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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 lua.lib.luasec;
|
||||
|
||||
import lua.lib.luasocket.socket.TcpClient;
|
||||
|
||||
extern class SslTcpClient extends TcpClient {
|
||||
function dohandshake():Result<Bool>;
|
||||
}
|
||||
@ -32,11 +32,6 @@ extern class Utf8 {
|
||||
**/
|
||||
static function sub(str:String, start:Int, ?end:Int):StringSub;
|
||||
|
||||
/**
|
||||
Returns the character code at position `index` of `str`.
|
||||
**/
|
||||
static function charCodeAt(str:String, index:Int):Int;
|
||||
|
||||
/**
|
||||
Looks for the first match of pattern in the string `str`.
|
||||
If it finds a match, then `find` returns the indices of `str` where this
|
||||
|
||||
@ -27,6 +27,6 @@ extern class Check extends Handle {
|
||||
static function new_check():Check;
|
||||
@:native("new_check") function new():Void;
|
||||
|
||||
function start(handle:Handle):Int;
|
||||
function start(cb:()->Void):Int;
|
||||
function stop():Int;
|
||||
}
|
||||
|
||||
@ -3,6 +3,11 @@ package lua.lib.luv;
|
||||
@:luaRequire("luv")
|
||||
extern class Loop {
|
||||
static function loop_close():Bool;
|
||||
/**
|
||||
Runs the event loop of libuv.
|
||||
|
||||
Haxe compiler automatically inserts a call to this function at the end of user's code if needed.
|
||||
**/
|
||||
static function run(?mode:String):Bool;
|
||||
static function loop_alive():Bool;
|
||||
static function stop():Void;
|
||||
|
||||
@ -27,11 +27,15 @@ import lua.Result;
|
||||
|
||||
@:luaRequire("luv")
|
||||
extern class FileSystem {
|
||||
static final constants:Table<String,Int>;
|
||||
|
||||
@:native("fs_close")
|
||||
@:overload(function(file:FileDescriptor, cb:String->Bool->Void):Request {})
|
||||
static function close(file:FileDescriptor):Result<Bool>;
|
||||
|
||||
@:native("fs_open")
|
||||
@:overload(function(path:String, flags:Int, mode:Int):Result<FileDescriptor> {})
|
||||
@:overload(function(path:String, flags:Int, mode:Int, ?cb:String->FileDescriptor->Void):Request {})
|
||||
@:overload(function(path:String, flags:Open, mode:Int, ?cb:String->FileDescriptor->Void):Request {})
|
||||
static function open(path:String, flags:Open, mode:Int):Result<FileDescriptor>;
|
||||
|
||||
@ -40,20 +44,24 @@ extern class FileSystem {
|
||||
static function read(file:FileDescriptor, len:Int, offset:Int):Result<String>;
|
||||
|
||||
@:native("fs_unlink")
|
||||
@:overload(function(file:FileDescriptor, ?cb:String->String->Void):Request {})
|
||||
static function unlink(file:FileDescriptor, content:String):Result<String>;
|
||||
@:overload(function(file:String, ?cb:String->Bool->Void):Request {})
|
||||
static function unlink(file:String, content:String):Result<Bool>;
|
||||
|
||||
@:native("fs_write")
|
||||
@:overload(function(file:FileDescriptor, content:String, offset:Int, ?cb:String->Bool->Void):Int {})
|
||||
static function write(file:FileDescriptor, content:String, offset:Int):Result<Bool>;
|
||||
@:overload(function(file:FileDescriptor, content:String, offset:Int, ?cb:String->Int->Void):Int {})
|
||||
static function write(file:FileDescriptor, content:String, offset:Int):Result<Int>;
|
||||
|
||||
@:native("fs_mkdir")
|
||||
@:overload(function(path:String, mode:Int, cb:String->Bool->Void):Request {})
|
||||
static function mkdir(path:String, mode:Int):Result<Bool>;
|
||||
|
||||
@:native("fs_mkdtemp")
|
||||
@:overload(function(data:String, cb:String->Bool->Void):Request {})
|
||||
static function mkdtemp(data:String):Result<Bool>;
|
||||
@:overload(function(template:String, cb:String->String->Void):Request {})
|
||||
static function mkdtemp(template:String):Result<String>;
|
||||
|
||||
@:native("fs_mkstemp")
|
||||
@:overload(function(template:String, cb:String->FileDescriptor->String->Void):Request {})
|
||||
static function mkstemp(template:String):Result<FileDescriptor>;
|
||||
|
||||
@:native("fs_rmdir")
|
||||
@:overload(function(path:String, cb:String->Bool->Void):Request {})
|
||||
@ -146,23 +154,27 @@ extern class FileSystem {
|
||||
Not available on windows
|
||||
**/
|
||||
@:native("fs_lchown")
|
||||
@:overload(function(descriptor:FileDescriptor, uid:Int, gid:Int, cb:String->Bool->Void):Request {})
|
||||
static function lchown(descriptor:FileDescriptor, uid:Int, gid:Int):Bool;
|
||||
@:overload(function(descriptor:String, uid:Int, gid:Int, cb:String->Bool->Void):Request {})
|
||||
static function lchown(descriptor:String, uid:Int, gid:Int):Bool;
|
||||
|
||||
@:native("fs_copyfile")
|
||||
@:overload(function(path:String, newPath:String, flags:Null<CopyFlags>, cb:String->Bool->Void):Request {})
|
||||
static function copyfile(path:String, newPath:String, ?flags:CopyFlags):Bool;
|
||||
|
||||
@:native("fs_statfs")
|
||||
@:overload(function(path:String, cb:StatFs->Bool->Void):Request {})
|
||||
static function statfs(path:String):StatFs;
|
||||
|
||||
@:native("fs_opendir")
|
||||
@:overload(function(path:String, cb:Handle->Bool->Void):Request {})
|
||||
@:overload(function(path:String, cb:String->Handle->Void, ?entries:Int):Request {})
|
||||
static function opendir(path:String):Handle;
|
||||
|
||||
@:native("fs_readdir")
|
||||
@:overload(function(dir:Handle, cb:Table<Int, NameType>->Bool->Void):Request {})
|
||||
static function readdir(path:String):Table<Int, NameType>;
|
||||
@:overload(function(dir:Handle, cb:String->Table<Int, NameType>->Void):Request {})
|
||||
static function readdir(path:Handle):Table<Int, NameType>;
|
||||
|
||||
@:native("fs_closedir")
|
||||
@:overload(function(dir:Handle, cb:Bool->Void):Request {})
|
||||
@:overload(function(dir:Handle, cb:String->Bool->Void):Request {})
|
||||
static function closedir(dir:Handle):Bool;
|
||||
}
|
||||
|
||||
@ -213,3 +225,24 @@ typedef StatFs = {
|
||||
files:Int,
|
||||
ffree:Int
|
||||
}
|
||||
|
||||
typedef CopyFlags = {
|
||||
?excl:Bool,
|
||||
?ficlone:Bool,
|
||||
?ficlone_force:Bool
|
||||
}
|
||||
|
||||
enum abstract AccessMode(Int) to Int {
|
||||
// from libuv sources
|
||||
|
||||
/* Test for read permission. */
|
||||
var R_OK = 4;
|
||||
/* Test for write permission. */
|
||||
var W_OK = 2;
|
||||
/* Test for execute permission. */
|
||||
var X_OK = 1;
|
||||
/* Test for existence. */
|
||||
var F_OK = 0;
|
||||
|
||||
@:op(A | B) function or(b:AccessMode):Int;
|
||||
}
|
||||
Reference in New Issue
Block a user