Browse Source

[lua] add missing feature check for _hx_bit_clamp, remove unnecessary heavyweight parseInt usage

Justin Donaldson 9 years ago
parent
commit
543d365aed
2 changed files with 16 additions and 14 deletions
  1. 9 8
      src/generators/genlua.ml
  2. 7 6
      std/lua/Boot.hx

+ 9 - 8
src/generators/genlua.ml

@@ -1806,18 +1806,12 @@ let generate com =
 		newline ctx
 	);
 
-
 	List.iter (generate_type_forward ctx) com.types; newline ctx;
 
-	(* Generate some dummy placeholders for bind/bit behavior that may be *)
-	(* generated later *)
+	(* Generate some dummy placeholders for utility libs that may be required*)
 	spr ctx "local _hx_bind,_hx_bit";
-	List.iter (gen__init__hoist ctx) (List.rev ctx.inits); newline ctx;
-	ctx.inits <- []; (* reset inits *)
 
-	List.iter (generate_type ctx) com.types;
-
-	if has_feature ctx "use._bitop" then begin
+	if has_feature ctx "use._bitop" || has_feature ctx "lua.Boot.clamp" then begin
 	    sprln ctx "pcall(require, 'bit32') pcall(require, 'bit')";
 	    sprln ctx "local _hx_bit_raw = bit or bit32";
 	    sprln ctx "local function _hx_bit_clamp(v) return _hx_bit_raw.band(v, 2147483647 ) - _hx_bit_raw.band(v, 2147483648) end";
@@ -1829,6 +1823,13 @@ let generate com =
 	    sprln ctx "end";
 	end;
 
+	List.iter (gen__init__hoist ctx) (List.rev ctx.inits); newline ctx;
+	ctx.inits <- []; (* reset inits after hoist *)
+
+	List.iter (generate_type ctx) com.types;
+
+
+
 	(* If we use haxe Strings, patch Lua's string *)
 	if has_feature ctx "use.string" then begin
 	    sprln ctx "local _hx_string_mt = _G.getmetatable('');";

+ 7 - 6
std/lua/Boot.hx

@@ -24,6 +24,7 @@ package lua;
 
 import haxe.Constraints.Function;
 
+
 @:dox(hide)
 class Boot {
 
@@ -278,7 +279,7 @@ class Boot {
 	   A 32 bit clamp function for integers
 	*/
 	public inline static function clamp(x:Int){
-		return untyped _hx_bit_clamp(x);
+		return untyped __define_feature__("lua.Boot.clamp", _hx_bit_clamp(x));
 	}
 
 	/*
@@ -292,19 +293,19 @@ class Boot {
 				year  : 0,
 				month : 1,
 				day   : 1,
-				hour  : Std.parseInt(k[0]),
-				min   : Std.parseInt(k[1]),
-				sec   : Std.parseInt(k[2])
+				hour  : Lua.tonumber(k[0]),
+				min   : Lua.tonumber(k[1]),
+				sec   : Lua.tonumber(k[2])
 			});
 			return std.Date.fromTime(t);
 		case 10: // YYYY-MM-DD
 			var k = s.split("-");
-			return new std.Date(Std.parseInt(k[0]), Std.parseInt(k[1]) - 1, Std.parseInt(k[2]),0,0,0);
+			return new std.Date(Lua.tonumber(k[0]), Lua.tonumber(k[1]) - 1, Lua.tonumber(k[2]),0,0,0);
 		case 19: // YYYY-MM-DD hh:mm:ss
 			var k = s.split(" ");
 			var y = k[0].split("-");
 			var t = k[1].split(":");
-			return new std.Date(cast y[0],Std.parseInt(y[1]) - 1, Std.parseInt(y[2]),Std.parseInt(t[0]),Std.parseInt(t[1]),Std.parseInt(t[2]));
+			return new std.Date(cast y[0],Lua.tonumber(y[1]) - 1, Lua.tonumber(y[2]),Lua.tonumber(t[0]),Lua.tonumber(t[1]),Lua.tonumber(t[2]));
 		default:
 			throw "Invalid date format : " + s;
 		}