Got it! :)
at first i dumped the ast:
World {.dumpAstGen.} = ref object
guids: GUID
storeHealthAble: Store[CompHealthAble]
storeDrawAble: Store[CompDrawAble]
storeNameAble: Store[CompNameAble]
Run
this works because the ast that generates this type is passed to the
dumpAstGen. Then i copied the ast into a new macro and added my generation
code. The only thing was that i had to put Components into its own type
section.:
type
Component = enum
DrawAble, HealthAble, NameAble, FOOAble
macro genWorld(left: typed, componentEnum: untyped) =
var typeTree = newNimNode(nnkRecList)
typeTree.add nnkIdentDefs.newTree(
newIdentNode("guids"),
newIdentNode("GUID"),
newEmptyNode()
)
for component in Component:
typeTree.add nnkIdentDefs.newTree(
newIdentNode("store" & $component ),
nnkBracketExpr.newTree(
newIdentNode("Store"),
newIdentNode("Comp" & $component)
),
newEmptyNode()
)
return nnkTypeDef.newTree(
nnkPragmaExpr.newTree(
newIdentNode("World"),
nnkPragma.newTree(
)
),
newEmptyNode(),
nnkRefTy.newTree(
nnkObjectTy.newTree(
newEmptyNode(),
newEmptyNode(),
typeTree
)
)
)
# another type section
type
World {.genWorld: Component.}
Run