# How to use metadata for reflect function?

**URL:** <https://community.haxe.org/t/how-to-use-metadata-for-reflect-function/1894>\
**Category:** Haxe\
**Created:** [July 11, 2019, 1:25pm UTC](https://community.haxe.org/t/how-to-use-metadata-for-reflect-function/1894 "2019-07-11T13:25:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zhan](https://community.haxe.org/user_avatar/community.haxe.org/zhan/32/468_2.png) [@Zhan](https://community.haxe.org/u/Zhan)\
**Post date:** [July 11, 2019, 1:25pm UTC](https://community.haxe.org/t/how-to-use-metadata-for-reflect-function/1894/1 "2019-07-11T13:25:15Z")

</div>

```
like here:

   @id(1)
public static function test1(id:Int, callFun:TinyPlayer->Void)

    @id(2)
public static function test2(id:Int, callFun:TinyPlayer->Void)

```

what I want to ask is are there any api to get test1 function from my custom metadata @id(1)

---

<div class="post-metadata">

**Author:** ![ibilon](https://community.haxe.org/user_avatar/community.haxe.org/ibilon/32/13_2.png) [@ibilon](https://community.haxe.org/u/ibilon)\
**Post date:** [July 11, 2019, 1:28pm UTC](https://community.haxe.org/t/how-to-use-metadata-for-reflect-function/1894/2 "2019-07-11T13:28:43Z")

</div>

There is using [`haxe.rtti.Meta`](https://api.haxe.org/haxe/rtti/Meta.html) see [Metadata - Haxe - The Cross-platform Toolkit](https://haxe.org/manual/lf-metadata.html).

edit: Oh you might have meant the other way, well you could add a build function to the class to look for them. [Type Building - Haxe - The Cross-platform Toolkit](https://haxe.org/manual/macro-type-building.html)  
or you could go through everything in [Context.onAfterTyping](https://api.haxe.org/haxe/macro/Context.html#onAfterTyping) or [Context.onGenerate](https://api.haxe.org/haxe/macro/Context.html#onGenerate) but you won’t be able to do much at that point.

---

<div class="post-metadata">

**Author:** ![Zhan](https://community.haxe.org/user_avatar/community.haxe.org/zhan/32/468_2.png) [@Zhan](https://community.haxe.org/u/Zhan)\
**Post date:** [July 11, 2019, 1:33pm UTC](https://community.haxe.org/t/how-to-use-metadata-for-reflect-function/1894/3 "2019-07-11T13:33:17Z")

</div>

thanks ,but why my id is an array instead of int?

var xxx = Meta.getStatics(Test).test1.id; //=Array[0]

btw;

what I want is revert to get method name “test1” from @id(1)

---

<div class="post-metadata">

**Author:** ![ibilon](https://community.haxe.org/user_avatar/community.haxe.org/ibilon/32/13_2.png) [@ibilon](https://community.haxe.org/u/ibilon)\
**Post date:** [July 11, 2019, 1:35pm UTC](https://community.haxe.org/t/how-to-use-metadata-for-reflect-function/1894/4 "2019-07-11T13:35:04Z")

</div>

Metas can have multiple parameters `@hello(this, other, some)` that’s why it is an array.

`haxe.rtti.Meta` won’t be able to do what you want, see my edit, but there’s nothing premade for that.

What are you trying to do?

---

<div class="post-metadata">

**Author:** ![Zhan](https://community.haxe.org/user_avatar/community.haxe.org/zhan/32/468_2.png) [@Zhan](https://community.haxe.org/u/Zhan)\
**Post date:** [July 11, 2019, 1:37pm UTC](https://community.haxe.org/t/how-to-use-metadata-for-reflect-function/1894/5 "2019-07-11T13:37:03Z")

</div>

from server socket ,get the mini data byte convert to function

from id=1 to convert to test1(id:Int, callFun:TinyPlayer-\>Void)

---

<div class="post-metadata">

**Author:** ![Zhan](https://community.haxe.org/user_avatar/community.haxe.org/zhan/32/468_2.png) [@Zhan](https://community.haxe.org/u/Zhan)\
**Post date:** [July 11, 2019, 1:38pm UTC](https://community.haxe.org/t/how-to-use-metadata-for-reflect-function/1894/6 "2019-07-11T13:38:20Z")

</div>

I 'm just remember there are a library name thinkbell? to do this,but I forgot how to do it as I did before?

---

<div class="post-metadata">

**Author:** ![ibilon](https://community.haxe.org/user_avatar/community.haxe.org/ibilon/32/13_2.png) [@ibilon](https://community.haxe.org/u/ibilon)\
**Post date:** [July 11, 2019, 1:46pm UTC](https://community.haxe.org/t/how-to-use-metadata-for-reflect-function/1894/7 "2019-07-11T13:46:03Z")

</div>

You can find all tinkerbell libraries here [https://haxetink.github.io/](https://haxetink.github.io/)  
Once you have found the one you need, using haxelib you can `haxelib install <lib>` and then add `-lib <lib>` to your hxml.

---

<div class="post-metadata">

**Author:** ![Zhan](https://community.haxe.org/user_avatar/community.haxe.org/zhan/32/468_2.png) [@Zhan](https://community.haxe.org/u/Zhan)\
**Post date:** [July 12, 2019, 1:58am UTC](https://community.haxe.org/t/how-to-use-metadata-for-reflect-function/1894/8 "2019-07-12T01:58:41Z")

</div>

can you give a tutorial about [GitHub - haxetink/tink\_websocket: WebSocket in Haxe](https://github.com/haxetink/tink_websocket) ?

it’s seem that can give something what I want.

@ibilon
