Răsfoiți Sursa

[lua] use initialization check for bit library presence instead of relying on -D lua_vanilla

Justin Donaldson 5 ani în urmă
părinte
comite
d32f65da88
3 a modificat fișierele cu 27 adăugiri și 24 ștergeri
  1. 1 4
      src/generators/genlua.ml
  2. 1 11
      std/lua/Boot.hx
  3. 25 9
      std/lua/_lua/_hx_bit_clamp.lua

+ 1 - 4
src/generators/genlua.ml

@@ -2060,10 +2060,7 @@ let generate com =
     List.iter (transform_multireturn ctx) com.types;
     List.iter (generate_type ctx) com.types;
 
-    if has_feature ctx "use._bitop" || has_feature ctx "lua.Boot.clamp" then begin
-        print_file (Common.find_file com "lua/_lua/_hx_bit_clamp.lua");
-        print_file (Common.find_file com "lua/_lua/_hx_bit.lua");
-    end;
+    print_file (Common.find_file com "lua/_lua/_hx_bit_clamp.lua");
 
     (* Array is required, always patch it *)
     println ctx "_hx_array_mt.__index = Array.prototype";

+ 1 - 11
std/lua/Boot.hx

@@ -302,17 +302,7 @@ class Boot {
 		A 32 bit clamp function for numbers
 	**/
 	public inline static function clampInt32(x:Float) {
-#if lua_vanilla
-		if (x < Min_Int32 ) {
-			return Min_Int32;
-		} else if (x > Max_Int32) {
-			return Max_Int32;
-		} else {
-			return Math.floor(x);
-		}
-#else
-		return untyped __define_feature__("lua.Boot.clamp", _hx_bit_clamp(x));
-#end
+        return untyped _hx_bit_clamp(x);
 	}
 
 	/**

+ 25 - 9
std/lua/_lua/_hx_bit_clamp.lua

@@ -1,10 +1,26 @@
-_hx_bit_clamp = function(v)
-  if v <= 2147483647 and v >= -2147483648 then
-    if v > 0 then return _G.math.floor(v)
-    else return _G.math.ceil(v)
+if _hx_bit_raw then
+    _hx_bit_clamp = function(v)
+    if v <= 2147483647 and v >= -2147483648 then
+        if v > 0 then return _G.math.floor(v)
+        else return _G.math.ceil(v)
+        end
     end
-  end
-  if v > 2251798999999999 then v = v*2 end;
-  if (v ~= v or math.abs(v) == _G.math.huge) then return nil end
-  return _hx_bit_raw.band(v, 2147483647 ) - math.abs(_hx_bit_raw.band(v, 2147483648))
-end
+    if v > 2251798999999999 then v = v*2 end;
+    if (v ~= v or math.abs(v) == _G.math.huge) then return nil end
+    return _hx_bit_raw.band(v, 2147483647 ) - math.abs(_hx_bit_raw.band(v, 2147483648))
+    end
+else
+    _hx_bit_clamp = function(v)
+        if v < -2147483648 then
+            return -2147483648
+        elseif v > 2147483647 then
+            return 2147483647
+        elseif v > 0 then
+            return _G.math.floor(v)
+        else
+            return _G.math.ceil(v)
+        end
+    end
+end;
+
+