【问题标题】:Using haxe.macro.TypeTools fails使用 haxe.macro.TypeTools 失败
【发布时间】:2016-07-13 20:13:38
【问题描述】:

我正在尝试调试使用haxe.macro.TypeTools::findField 的库。我为此创建了一个简单的代码:

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() {}
}

但是我收到错误Unknown identifier : findField。这是因为它只能在构建宏上下文中使用吗?

This 是我想要模仿的。

【问题讨论】:

    标签: macros haxe


    【解决方案1】:

    首先,函数findField()不是来自haxe.macro.TypeTools。 是a helper function from edge.core.macro.Macros

    要在没有类路径的情况下使用它,请使用通配符 import edge.core.macro.Macros.* 导入它的类

    其次,findField() 应该只在构建宏上下文中使用,因为它需要 Array<Field>,这是由 haxe.macro.Context.getBuildFields() 获得的。

    【讨论】:

    • 谢谢!还有一个问题:那github.com/HaxeFoundation/haxe/blob/…怎么用?
    • 好的,我通读了静态扩展文档页面,所以它会被称为:SomeClassType.findField("field", true);
    • 是的,但仅在宏上下文中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-09
    • 2021-11-24
    • 2016-10-17
    • 2013-01-15
    • 2018-01-14
    • 1970-01-01
    相关资源
    最近更新 更多