[英]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.