No, can not access the const with constructed name inside the macro
import macros
const CX = 7
proc genVar(c: static[string]): NimNode {.compiletime.} =
result = newNimNode(nnkStmtList)
var
section = newNimNode(nnkVarSection)
constDef = newNimNode(nnkIdentDefs)
constDef.add(newIdentNode("myvar"))
constDef.add(newEmptyNode())
constDef.add(newIdentNode("C" & $c))
section.add(constDef)
result.add(section)
macro t(s: static[string]): typed =
genVar($s)
if myVar == 7:
echo "GREAT"
t("X")
- Identifier constructon in macro -- no success Stefan_Salewski
- Re: Identifier constructon in macro -- no success Parashurama
- Re: Identifier constructon in macro -- no success Stefan_Salewski
- Re: Identifier constructon in macro -- no suc... Stefan_Salewski
- Re: Identifier constructon in macro -- no... Stefan_Salewski
