Browse Source

introduce @:hlNative version marker for automatic fallback on throw

Nicolas Cannasse 6 years ago
parent
commit
08f382af0e
2 changed files with 10 additions and 1 deletions
  1. 9 0
      src/generators/genhl.ml
  2. 1 1
      std/hl/_std/Date.hx

+ 9 - 0
src/generators/genhl.ml

@@ -3290,6 +3290,15 @@ let generate_static ctx c f =
 				add_native lib name
 				add_native lib name
 			| (Meta.HlNative,[(EConst(String(lib)),_)] ,_ ) :: _ ->
 			| (Meta.HlNative,[(EConst(String(lib)),_)] ,_ ) :: _ ->
 				add_native lib f.cf_name
 				add_native lib f.cf_name
+			| (Meta.HlNative,[(EConst(Float(ver)),_)] ,_ ) :: _ ->
+				let cur_ver = (try Common.raw_defined_value ctx.com "hl-ver" with Not_found -> "") in
+				if cur_ver < ver then
+					let gen_content() =
+						op ctx (OThrow (make_string ctx ("Requires compiling with -D hl-ver=" ^ ver ^ " or higher") null_pos));
+					in
+					ignore(make_fun ctx ~gen_content (s_type_path c.cl_path,f.cf_name) (alloc_fid ctx c f) (match f.cf_expr with Some { eexpr = TFunction f } -> f | _ -> abort "Missing function body" f.cf_pos) None None)
+				else
+				add_native "std" f.cf_name
 			| (Meta.HlNative,[] ,_ ) :: _ ->
 			| (Meta.HlNative,[] ,_ ) :: _ ->
 				add_native "std" f.cf_name
 				add_native "std" f.cf_name
 			| (Meta.HlNative,_ ,p) :: _ ->
 			| (Meta.HlNative,_ ,p) :: _ ->

+ 1 - 1
std/hl/_std/Date.hx

@@ -183,7 +183,7 @@ import hl.Ref;
 		return 0.;
 		return 0.;
 	}
 	}
 
 
-	@:hlNative
+	@:hlNative(1.11)
 	static function date_get_inf(t:Int, year:Ref<Int>, month:Ref<Int>, day:Ref<Int>, hours:Ref<Int>, minutes:Ref<Int>, seconds:Ref<Int>, wday:Ref<Int>):Void {}
 	static function date_get_inf(t:Int, year:Ref<Int>, month:Ref<Int>, day:Ref<Int>, hours:Ref<Int>, minutes:Ref<Int>, seconds:Ref<Int>, wday:Ref<Int>):Void {}
 
 
 	@:hlNative
 	@:hlNative