【发布时间】: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。没有宏部分,它工作得很好。
经过几个小时的研究,我没有发现问题,所以感谢您查看。
【问题讨论】: