Explorar o código

added Compiler.addNativeLib (fixed issue #1099)

Nicolas Cannasse %!s(int64=13) %!d(string=hai) anos
pai
achega
172e94a3e4
Modificáronse 5 ficheiros con 48 adicións e 30 borrados
  1. 2 2
      Makefile
  2. 27 0
      genswf.ml
  3. 11 0
      interp.ml
  4. 1 28
      main.ml
  5. 7 0
      std/haxe/macro/Compiler.hx

+ 2 - 2
Makefile

@@ -30,7 +30,7 @@ EXPORT=../../../projects/motionTools/haxe
 
 MODULES=ast type lexer common genxml parser typecore optimizer typeload \
 	codegen genas3 gencommon gencpp genjs genneko genphp genswf8 \
-	gencs genjava genswf9 interp genswf typer dce main
+	gencs genjava genswf9 genswf interp typer dce main
 
 HAXE_LIBRARY_PATH=$(CURDIR)/std
 
@@ -90,7 +90,7 @@ genswf9.cmx: type.cmx lexer.cmx genswf8.cmx common.cmx codegen.cmx ast.cmx
 
 genxml.cmx: type.cmx lexer.cmx common.cmx ast.cmx
 
-interp.cmx: typecore.cmx type.cmx lexer.cmx genneko.cmx common.cmx codegen.cmx ast.cmx
+interp.cmx: typecore.cmx type.cmx lexer.cmx genneko.cmx common.cmx codegen.cmx ast.cmx genswf.cmx
 
 main.cmx: dce.cmx typer.cmx typeload.cmx typecore.cmx type.cmx parser.cmx optimizer.cmx lexer.cmx interp.cmx genxml.cmx genswf.cmx genphp.cmx genneko.cmx genjs.cmx genjava.cmx gencs.cmx gencpp.cmx genas3.cmx common.cmx codegen.cmx ast.cmx
 

+ 27 - 0
genswf.ml

@@ -530,6 +530,33 @@ let parse_swf com file =
 	t();
 	(h,tags)
 
+let add_swf_lib com file =
+	let swf_data = ref None in
+	let swf_classes = ref None in
+	let getSWF = (fun() ->
+		match !swf_data with
+		| None ->
+			let d = parse_swf com file in
+			swf_data := Some d;
+			d
+		| Some d -> d
+	) in
+	let extract = (fun() ->
+		match !swf_classes with
+		| None ->
+			let d = extract_data (getSWF()) in
+			swf_classes := Some d;
+			d
+		| Some d -> d
+	) in
+	let build cl p =
+		match (try Some (Hashtbl.find (extract()) cl) with Not_found -> None) with
+		| None -> None
+		| Some c -> Some (file, build_class com c file)
+	in
+	com.load_extern_type <- com.load_extern_type @ [build];
+	com.swf_libs <- (file,getSWF,extract) :: com.swf_libs
+
 (* ------------------------------- *)
 
 let tag ?(ext=false) d = {

+ 11 - 0
interp.ml

@@ -2258,6 +2258,17 @@ let macro_lib =
 			| _ ->
 				error()
 		);
+		"add_native_lib", Fun1 (fun v ->
+			match v with
+			| VString file ->
+				let com = ccom() in
+				(match com.platform with
+				| Flash -> Genswf.add_swf_lib com file
+				| _ -> failwith "Unsupported platform");
+				VNull
+			| _ ->
+				error()
+		);
 		"module_dependency", Fun2 (fun m file ->
 			match m, file with
 			| VString m, VString file ->

+ 1 - 28
main.ml

@@ -264,33 +264,6 @@ let lookup_classes com spath =
 	in
 	loop com.class_path
 
-let add_swf_lib com file =
-	let swf_data = ref None in
-	let swf_classes = ref None in
-	let getSWF = (fun() ->
-		match !swf_data with
-		| None ->
-			let d = Genswf.parse_swf com file in
-			swf_data := Some d;
-			d
-		| Some d -> d
-	) in
-	let extract = (fun() ->
-		match !swf_classes with
-		| None ->
-			let d = Genswf.extract_data (getSWF()) in
-			swf_classes := Some d;
-			d
-		| Some d -> d
-	) in
-	let build cl p =
-		match (try Some (Hashtbl.find (extract()) cl) with Not_found -> None) with
-		| None -> None
-		| Some c -> Some (file, Genswf.build_class com c file)
-	in
-	com.load_extern_type <- com.load_extern_type @ [build];
-	com.swf_libs <- (file,getSWF,extract) :: com.swf_libs
-
 let add_libs com libs =
 	let call_haxelib() =
 		let t = Common.timer "haxelib" in
@@ -823,7 +796,7 @@ try
 				_ -> raise (Arg.Bad "Invalid SWF header format")
 		),"<header> : define SWF header (width:height:fps:color)");
 		("-swf-lib",Arg.String (fun file ->
-			add_swf_lib com file
+			Genswf.add_swf_lib com file
 		),"<file> : add the SWF library to the compiled SWF");
 		("-x", Arg.String (fun file ->
 			let neko_file = file ^ ".n" in

+ 7 - 0
std/haxe/macro/Compiler.hx

@@ -69,6 +69,13 @@ class Compiler {
 		untyped load("set_output",1)(untyped fileOrDir.__s);
 	}
 
+	/**
+		Adds a native library depending on the platform (eg : -swf-lib for Flash)
+	**/
+	public static function addNativeLib( name : String ) {
+		return untyped load("add_native_lib",1)(name.__s);
+	}
+
 	/**
 		Include for compilation all classes defined in the given package excluding the ones referenced in the ignore list.
 	**/