Misiur
Misiur

Reputation: 5307

Using haxe.macro.TypeTools fails

I'm trying to debug a library which uses haxe.macro.TypeTools::findField. I've created a simple code for that:

package;

using haxe.macro.TypeTools;

class Main
{   
    public function new()
    {   
        var test = findField(Child, "hello");
        trace(test);
    }
}

class Base
{
    private function hello()
    {
    }
}

class Child extends Base
{
    public function new() {}
}

However I'm getting error Unknown identifier : findField. Is this because it can only be used in build macro context?

This is what I'm trying to emulate.

Upvotes: 1

Views: 67

Answers (1)

Mihail Ignatiev
Mihail Ignatiev

Reputation: 853

First of all, function findField() is not from the haxe.macro.TypeTools. It is a helper function from edge.core.macro.Macros.

To use it without a class path, import it's class with a wildcard import edge.core.macro.Macros.*

Secondly, findField() should be used in a build macro context only, since it expects Array<Field>, which is obtained by haxe.macro.Context.getBuildFields().

Upvotes: 2

Related Questions