Ver Fonte

Lua: Fix reading in32 from Input

Justin Donaldson há 10 anos atrás
pai
commit
9d5c5bc430
1 ficheiros alterados com 10 adições e 5 exclusões
  1. 10 5
      std/haxe/io/Input.hx

+ 10 - 5
std/haxe/io/Input.hx

@@ -278,11 +278,16 @@ class Input {
 		var ch3 = readByte();
 		var ch4 = readByte();
 #if (php || python)
-        // php will overflow integers.  Convert them back to signed 32-bit ints.
-        var n = bigEndian ? ch4 | (ch3 << 8) | (ch2 << 16) | (ch1 << 24) : ch1 | (ch2 << 8) | (ch3 << 16) | (ch4 << 24);
-        if (n & 0x80000000 != 0)
-            return ( n | 0x80000000);
-        else return n;
+		// php will overflow integers.  Convert them back to signed 32-bit ints.
+		var n = bigEndian ? ch4 | (ch3 << 8) | (ch2 << 16) | (ch1 << 24) : ch1 | (ch2 << 8) | (ch3 << 16) | (ch4 << 24);
+		if (n & 0x80000000 != 0)
+		    return ( n | 0x80000000);
+		else return n;
+#elseif lua
+		var n = bigEndian ? ch4 | (ch3 << 8) | (ch2 << 16) | (ch1 << 24) : ch1 | (ch2 << 8) | (ch3 << 16) | (ch4 << 24);
+		// lua can't do 32 bit ints, the adjustment for 64 bits must be numeric
+		if (n > 2147483647) n -=  untyped 4294967296.;
+		return n ;
 #else
 		return bigEndian ? ch4 | (ch3 << 8) | (ch2 << 16) | (ch1 << 24) : ch1 | (ch2 << 8) | (ch3 << 16) | (ch4 << 24);
 #end