[英]Haxe Macro : Result an invalid access static
我在 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
。 没有宏部分,它工作得很好。
经过几个小时的研究,我还没有找到问题所在,所以感谢您的关注。
我发现了问题,我误解了genericBuild
工作原理,感谢所有阅读的人。
实际上,代码在类型T
上执行一个函数,这是不可能的,这就是抛出错误的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.