oh I'll post an example
type PkgInstall* = object
pkg*: Pkg
version*: PkgVer
layout*: PkgLayout
macro `.`*(pkg: PkgInstall, field: string): untyped =
## ^ This makes PkgInstall types act like contatinations
## of the Pkg, PkgVer and PkgLayout types
var subfields = pkg.getType.last
expectKind(subfields, nnkRecList)
for elm in subfields:
var fields = elm.getType.last
expectKind(fields, nnkRecList)
var real_field = findChild(fields, eqIdent(it, $field))
if real_field != nil:
result = newDotExpr(pkg, elm).newDotExpr real_field
return
template `.=`*(pkg: PkgInstall, field: string, rval: untyped) =
`.`(pkg, field) = rval
Obviously needs {.experimental.} and it's really only for that one type as of
now.