Nicolas Cannasse 14 лет назад
Родитель
Сommit
1beade221b
2 измененных файлов с 12 добавлено и 0 удалено
  1. 5 0
      interp.ml
  2. 7 0
      std/haxe/macro/Context.hx

+ 5 - 0
interp.ml

@@ -1678,6 +1678,11 @@ let macro_lib =
 			| VInt min, VInt max, VString file -> VAbstract (APos { Ast.pmin = min; Ast.pmax = max; Ast.pfile = file })
 			| _ -> error()
 		);
+		"add_resource", Fun2 (fun name data ->
+			match name, data with
+			| VString name, VString data -> Hashtbl.replace (get_ctx()).com.Common.resources name data; VNull
+			| _ -> error()
+		);
 	]
 
 (* ---------------------------------------------------------------------- *)

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

@@ -135,6 +135,13 @@ class Context {
 		return load("make_pos",3)(inf.min,inf.max,untyped inf.file.__s);
 	}
 
+	/**
+		Add or modify a resource that will be accessible with haxe.Resource api.
+	**/
+	public static function addResource( name : String, data : haxe.io.Bytes ) {
+		return load("add_resource",2)(untyped name.__s,data.getData());
+	}
+
 	static function load( f, nargs ) : Dynamic {
 		#if macro
 		return neko.Lib.load("macro", f, nargs);