Explorar o código

[lua] make random seed based on the presence of new Math.random feature

Justin Donaldson %!s(int64=9) %!d(string=hai) anos
pai
achega
c28916ce7b
Modificáronse 3 ficheiros con 5 adicións e 7 borrados
  1. 4 0
      src/generators/genlua.ml
  2. 0 3
      std/lua/Math.hx
  3. 1 4
      std/lua/_std/Math.hx

+ 4 - 0
src/generators/genlua.ml

@@ -1884,6 +1884,10 @@ let generate com =
 	    println ctx "end";
 	end;
 
+	if has_feature ctx "Math.random" then begin
+	    println ctx "_G.math.randomseed(_G.os.time());"
+	end;
+
 
 	List.iter (generate_enumMeta_fields ctx) com.types;
 

+ 0 - 3
std/lua/Math.hx

@@ -39,8 +39,5 @@ extern class Math {
 
 	public static function random() : Float;
 	public static function randomseed(i : Float) : Float;
-
-	//  initialize the random seed with the current time
-	public static function __init__() : Void randomseed(Os.time());
 }
 

+ 1 - 4
std/lua/_std/Math.hx

@@ -57,7 +57,7 @@ class Math
 	public static inline function floor(v:Float):Int  return lua.Math.floor(v);
 	public static inline function log(v:Float):Float  return lua.Math.log(v);
 
-	public static inline function random() : Float    return lua.Math.random();
+	public static inline function random() : Float return untyped __define_feature__("Math.random", lua.Math.random());
 
 	public static inline function atan2(y:Float, x:Float):Float return lua.Math.atan2(y,x);
 	public static inline function max(a:Float, b:Float):Float {
@@ -74,7 +74,4 @@ class Math
 	public static inline function fceil( v : Float ) : Float return ceil(v);
 	public static inline function fround( v : Float ) : Float return round(v);
 
-	static function __init__() : Void {
-		untyped __feature__("Type.resolveClass", _hxClasses["Math"] = Math);
-	}
 }