2
0
Эх сурвалжийг харах

Merge pull request #2571 from frabbit/get_resources

add getResources to haxe.macro.Context
Simon Krajewski 11 жил өмнө
parent
commit
a71c145d62
2 өөрчлөгдсөн 21 нэмэгдсэн , 0 устгасан
  1. 6 0
      interp.ml
  2. 15 0
      std/haxe/macro/Context.hx

+ 6 - 0
interp.ml

@@ -2400,6 +2400,12 @@ let macro_lib =
 				VNull
 			| _ -> error()
 		);
+        "get_resources", Fun0 (fun() ->
+			let res = (ccom()).resources in
+			let h = Hashtbl.create 0 in
+			Hashtbl.iter (fun n v -> Hashtbl.replace h (VString n) (VString v)) res;
+			enc_hash h
+		);
 		"local_module", Fun0 (fun() ->
 			let m = (get_ctx()).curapi.current_module() in
 			VString (Ast.s_type_path m.m_path);

+ 15 - 0
std/haxe/macro/Context.hx

@@ -348,6 +348,21 @@ class Context {
 		return load("make_pos",3)(inf.min,inf.max,untyped inf.file.__s);
 	}
 
+	/**
+		Returns a map of all registered resources for this compilation unit.
+
+		Modifying the returned map has no effect on the compilation, use
+		`haxe.macro.Context.addResource` to add new resources to the compilation unit.
+	**/
+	public static function getResources():haxe.ds.StringMap<haxe.io.Bytes> {
+		var x:haxe.ds.StringMap<neko.NativeString> = load("get_resources",0)();
+		var r = new haxe.ds.StringMap();
+		for (k in x.keys()) {
+			r.set(k, haxe.io.Bytes.ofData(x.get(k)));
+		} 
+		return r;
+	}
+
 	/**
 		Makes resource `data` available as `name`.