Sfoglia il codice sorgente

Lua : update _hx_bit library to handle signed bnot, and expose _hx_bit_clamp

Justin Donaldson 9 anni fa
parent
commit
14f53043eb
3 ha cambiato i file con 13 aggiunte e 9 eliminazioni
  1. 1 0
      std/lua/Bit.hx
  2. 5 5
      std/lua/Boot.hx
  3. 7 4
      std/lua/_lua/_hx_bit.lua

+ 1 - 0
std/lua/Bit.hx

@@ -36,6 +36,7 @@ extern class Bit {
 	public static function arshift(x:Float, places:Int) : Int;
 	public static function mod(numerator:Float, denominator:Float) : Int;
 	public static function __init__() : Void {
+		//bit library fixes
 		haxe.macro.Compiler.includeFile("lua/_lua/_hx_bit.lua");
 	}
 }

+ 5 - 5
std/lua/Boot.hx

@@ -170,7 +170,7 @@ class Boot {
 		}
 	}
 
-	static function printClass(c:Table<String,Dynamic>, s : String) : String {
+	static inline function printClass(c:Table<String,Dynamic>, s : String) : String {
 		return '{${printClassRec(c,'',s)}}';
 
 	}
@@ -233,7 +233,7 @@ class Boot {
 		return cast defArray(t,length);
 	}
 
-	public static function defArray<T>(tab: Table<Int,T>, length : Int) : Array<T> {
+	public inline static function defArray<T>(tab: Table<Int,T>, length : Int) : Array<T> {
 		return untyped _hx_tabArray(tab, length);
 	}
 
@@ -255,8 +255,8 @@ class Boot {
 			+":"+(if( s < 10 ) "0"+s else ""+s);
 	}
 
-	public static function clamp(x:Int){
-		return (x & 2147483647) - (x & cast 2147483648);
+	public inline static function clamp(x:Int){
+		return untyped _hx_bit_clamp(x);
 	}
 
 	public static function strDate( s : String ) : std.Date {
@@ -285,7 +285,7 @@ class Boot {
 		}
 	}
 
-	public static function createTable<K,V>() : Table<K,V> {
+	public inline static function createTable<K,V>() : Table<K,V> {
 		return untyped __lua__("{}");
 	}
 

+ 7 - 4
std/lua/_lua/_hx_bit.lua

@@ -1,9 +1,12 @@
 local _hx_bit
 pcall(require, 'bit32') pcall(require, 'bit')
+local _hx_bit_raw = bit or bit32
+
+local function _hx_bit_clamp(v) return _hx_bit_raw.band(v, 2147483647 ) - _hx_bit_raw.band(v, 2147483648) end
+
 if type(jit) == 'table' then
-  local _hx_bit_raw = bit or bit32
-  local function _hx_bitfix(v) return (v >= 0) and v or (4294967296 + v) end
-  _hx_bit = setmetatable({},{__index = function(t,k) return function(...) return _hx_bitfix(rawget(_hx_bit_raw,k)(...)) end end})
+  _hx_bit = setmetatable({},{__index = function(t,k) return function(...) return _hx_bit_clamp(rawget(_hx_bit_raw,k)(...)) end end})
 else
-  _hx_bit = bit or bit32
+  _hx_bit = setmetatable({}, { __index = _hx_bit_raw })
+  _hx_bit.bnot = function(...) return _hx_bit_clamp(_hx_bit_raw.bnot(...)) end
 end