Переглянути джерело

rework MetaAccess.extract to return array of metas with given name.

Dan Korostelev 10 роки тому
батько
коміт
892b1cb5f6
2 змінених файлів з 4 додано та 9 видалено
  1. 1 5
      interp.ml
  2. 3 4
      std/haxe/macro/Type.hx

+ 1 - 5
interp.ml

@@ -4255,11 +4255,7 @@ let encode_meta m set =
 		));
 		"extract", VFunction (Fun1 (fun k ->
 			let k = MetaInfo.from_string (try dec_string k with Invalid_expr -> raise Builtin_error) in
-			try
-				let entry = List.find (fun (m,_,_) -> m = k) (!meta) in
-				encode_meta_entry entry
-			with Not_found ->
-				VNull
+			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

+ 3 - 4
std/haxe/macro/Type.hx

@@ -203,14 +203,13 @@ typedef MetaAccess = {
 	function get() : Expr.Metadata;
 
 	/**
-		Extract metadata entry by given `name`.
+		Extract metadata entries by given `name`.
 
-		If there's no metadata with such name, null will be returned.
-		If there's more than one entry with such name, the first one will be returned.
+		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 ) : Expr.MetadataEntry;
+	function extract( name : String ) : Array<Expr.MetadataEntry>;
 
 	/**
 		Adds the metadata specified by `name`, `params` and `pos` to the origin