Browse Source

[lua] Fix for https requests failing immediately and updating _hx_bit to work with lua 5.4 (#11052)

* Adds override function close to Lua SSL Socket to fix HTTPS requests.

* Fix extra space

* Fix _hx_bit to work with lua 5.1 through 5.4

* Replace tab with spaces
David Bruce 2 years ago
parent
commit
d15a6d69da
2 changed files with 18 additions and 11 deletions
  1. 13 9
      std/lua/_lua/_hx_bit.lua
  2. 5 2
      std/lua/_std/sys/ssl/Socket.hx

+ 13 - 9
std/lua/_lua/_hx_bit.lua

@@ -1,17 +1,21 @@
-if pcall(require, 'bit32') then --if we are on Lua 5.1, bit32 will be the default. 
+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 });
+  _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'
-  pcall(require, '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 });
+  _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

+ 5 - 2
std/lua/_std/sys/ssl/Socket.hx

@@ -62,5 +62,8 @@ class Socket extends sys.net.Socket {
 		_sslSocket.settimeout(timeout);
         this.handshake();
     }
- }
- 
+
+    public override function close():Void {
+		_sslSocket.close();
+    }
+}