Accessing runtime metadata from hashlink

(Lee) #1

hey i want to annotate arbitrary fields (specific classes, functions, variables, properties, etc) with runtime metadata, and then access them from C. I noticed if i compile to hl/c the metadata for each field is there, but I can’t find it when i’m just running standard hl bytecode.
I could probably setup something on the haxe side to register everything that has these metadata tags, but i’d much prefer to iterate through types and fields and store them off, but i got nothing when i’m looking at each type through either hl_get_obj_rt or hl_get_obj_proto. Am i looking in the wrong place, and is there a way to do this on the C-side of things?



(Nicolas Cannasse) #2

The Haxe side metadata is store in a way that it can be accessed using haxe Api (haxe.rtti.Meta).
So if you want to access it from C you need to use the same way it does, see #if hl parts in haxe/std/haxe/rtti/Meta.hx

Basically you need to read the “global value” (which is the class bound to a given instance) from the object prototype, then cast it to BaseType and access its __meta__