Hello! I am learning to use macros in Nim and I am trying to define e.g. a macro that will be used like this:
mymacro(foo: int)
However, I am getting the error "object constructor needs an object type". It seems that the code in the macro that I have defined doesn't run at all and it fails some point before macros are run. Is there a way to bypass this error?
Thank you!
Or, maybe you want to call your macro like this
mymacro:
foo: int
bar: string
macro mymacro(fields) =
expectKind fields, nnkStmtList
for f in fields:
expectKind f, nnkCall
expectKind f[0], nnkIdent
expectKind f[1], nnkStmtList
expectKind f[1][0], nnkIdent
echo f[0].strVal # field name
echo f[1][0].strVal # field type