template tpl(name:string, body:untyped):untyped =
proc `name Free`()=
body
tpl("myname"):
echo "1"
echo "2"
mynameFree()
What am I missing to make it work?
Secondly, how could I inspect what the template is generating?
instead of a string use untyped, i.e.
template tpl(name:untyped, body:untyped):untyped =
proc `name Free`()=
body
tpl(myname):
echo "1"
echo "2"
mynameFree()
tpl(myname):
echo "1"
echo "2"
gets converted into:
proc mynameFree() =
echo "1"
echo "2"
Use expandMacros, like below:
import macros
template tpl(name: untyped, body: untyped): untyped =
proc `name Free`()=
body
expandMacros:
tpl(myname):
echo "1"
echo "2"
mynameFree()