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

Merge pull request #3625 from nadako/meta_extract

add MetaAccess.extract function
Dan Korostelev 10 жил өмнө
parent
commit
5846644b8a
2 өөрчлөгдсөн 13 нэмэгдсэн , 0 устгасан
  1. 4 0
      interp.ml
  2. 9 0
      std/haxe/macro/Type.hx

+ 4 - 0
interp.ml

@@ -4253,6 +4253,10 @@ let encode_meta m set =
 				failwith "Invalid expression");
 			VNull
 		));
+		"extract", VFunction (Fun1 (fun k ->
+			let k = MetaInfo.from_string (try dec_string k with Invalid_expr -> raise Builtin_error) in
+			encode_array encode_meta_entry (List.filter (fun (m,_,_) -> m = k) (!meta))
+		));
 		"remove", VFunction (Fun1 (fun k ->
 			let k = MetaInfo.from_string (try dec_string k with Invalid_expr -> raise Builtin_error) in
 			meta := List.filter (fun (m,_,_) -> m <> k) (!meta);

+ 9 - 0
std/haxe/macro/Type.hx

@@ -202,6 +202,15 @@ typedef MetaAccess = {
 	**/
 	function get() : Expr.Metadata;
 
+	/**
+		Extract metadata entries by given `name`.
+
+		If there's no metadata with such name, empty array is returned.
+
+		If `name` is null, compilation fails with an error.
+	**/
+	function extract( name : String ) : Array<Expr.MetadataEntry>;
+
 	/**
 		Adds the metadata specified by `name`, `params` and `pos` to the origin
 		of `this` MetaAccess.