【问题标题】:Haxe Macro : Result an invalid access staticHaxe 宏:导致无效的访问静态
【发布时间】:2015-09-05 16:53:08
【问题描述】:

我在 Haxe 中遇到了一些问题,实际上无法解决。我也找不到任何关于宏的好文档,所以如果你知道,如果你分享,我将不胜感激。

代码如下:

class ProfilesContainerBuilder {
#if macro
    public static function build() : ComplexType {
        var fields = new Array<Field>();
        switch (Context.getLocalType()) {
            case TInst(_, [t1]):
                fields.push({
                    name: "get",
                    access: [APublic,AStatic],
                    pos: Context.currentPos(),
                    kind: FieldType.FVar(Context.getLocalType().toComplexType(),null)
                });
                fields.push({
                    name: "profile",
                    access: [APublic,AStatic],
                    pos: Context.currentPos(),
                    kind: FieldType.FVar(t1.toComplexType(),null)
                });
                fields.push({
                    name: "_getProfile",
                    access: [],
                    pos: Context.currentPos(),
                    kind: FieldType.FFun({
                        args: [],
                        expr: { pos: Context.currentPos(), expr: EReturn(
                            macro $i{t1.getClass().name+'.fromDynamic(Json.parse(Assets.getText("profiles/"+_activeProfile+".json")))'} )},
                        params: [],
                        ret: t1.toComplexType()
                    })
                });
            default:
                Context.error("Class expected", Context.currentPos());
        }
        return TAnonymous(fields);
    }
#end
}
@:remove @:genericBuild(brocchinia.io.ressource.ProfilesContainerBuilder.build())
extern interface ProfilesContainer<T> { }

然后,这是给定的错误,在一个实现构建接口的类中:

C:/HaxeToolkit/haxe/lib/brocchinia/0,1,0/brocchinia/io/ressource/Ressource.hx:27:第 27-114 行:静态访问无效

知道我从静态和本地函数访问变量 get、profile 和函数 _getProfile。没有宏部分,它工作得很好。

经过几个小时的研究,我没有发现问题,所以感谢您查看。

【问题讨论】:

    标签: macros haxe


    【解决方案1】:

    我发现了问题,我误解了genericBuild 的工作原理,感谢所有阅读的人。

    实际上,代码在T类型上执行了一个函数,这是不可能的,这就是抛出错误的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-26
      • 1970-01-01
      • 1970-01-01
      • 2011-03-24
      相关资源
      最近更新 更多