Enums and @:rtti

If I add @:rtti metadata to an enum, I can’t seem to find an __rtti field, like I can for a class.

import haxe.rtti.Rtti;

class MyClass {
	static function main() {
		trace(Reflect.field(MyOtherClass, "__rtti")); // { ...omitted... }
		trace(Reflect.field(MyEnum, "__rtti")); // null

enum MyEnum {
	Two(a:String, b:Float);

class MyOtherClass {}

Is there any other option? I’d like to be able to determine at runtime which parameters are defined (including their names and types) for MyEnum.Two(). Just like I can do for methods on a class.

Interestingly, reviewing the haxe.rtti.XmlParser source code, it seems capable of parsing RTTI data for enums and abstracts.

I guess I could try to generate the XML data myself in a macro. It looks like the format isn’t officially documented, but I can probably figure it out based on what XmlParser is doing. It would certainly save me time if the compiler could generate RTTI for enums and abstracts for me, though, so if anyone has any idea how to force the compiler to do that, I’d still greatly appreciate it!

EDIT: Aha! I see that it’s the same format used for XML data passed to dox. Thankfully, now I have some examples of XML for enums and abstracts to work from for generating it manually. That also explains why XmlParser is capable of handling those types, even if the compiler doesn’t seem to generate it for @:rtti.

1 Like