Here is the code:
import macros, times, strutils
type Data* = object
value*: int
fvalue*: float
tvalue*: Time
iterator objfields(t: typedesc): (NimNode, NimNode) =
let reclist = t.getType[1]
for i in 0..len(reclist)-1:
echo reclist[i].getType.treeRepr
yield (reclist[i], reclist[i].getType)
macro test(): stmt =
result = newStmtList()
for n, t in Data.objfields:
let i = $n
let i2 = $t
let s = quote do:
echo `i`, ", ", `i2`
result.add(s)
test()
It works with simple type fields (value, fvalue). But it fails with error
Error: unhandled exception: false Invalid node kind nnkBracketExpr for macros.`$`
for field tvalue. After adding echo to the iterator, it shows this types for fields:
Sym "int"
Sym "float"
BracketExpr
Sym "distinct"
Sym "int"
How can I get Sym "Time" for tvalue field in this example?