You don't need anything special for this. Just the usual rules apply for cross-module use: if the macro is defined in one module and the procedure created by it is used in another, then just mark with * (as exported symbol) either the macro itself (if it will be called in the second module, so that the procedure will be created in that) or the procedure (if the macro will be called in the first module, in which it is defined - then you don't need to import the macro, instead the proc to which it expanded).
Happy New Year to everyone!
Use macros.bindSym for clean symbol bindings.
Happy New Year!
Thanks for your reply, LeuGim, but the case that I was talking about it the opposite. What if a macro calls a proc that needs to be imported?
Araq: could you elaborate on this?
There should be nothing special for this case, if the macro is used in the same module, where defined. You just need to use import before calling the macro (but can use after the macro definition itself).
If the proc is defined in one module (a), the macro in another (b) and is called in yet another (c), then you need either:
E.g.:
# module a
proc p* = echo "p of a"
proc pv* {.procvar.} = echo "pv of a"
#module a2
proc p* = echo "p of a2"
# module b
import a
import macros
macro x1*: untyped =
result = newNimNode(nnkStmtList)
result.add newCall(bindSym"p")
# the same
macro x2*: untyped =
result = quote do:
bind p
p()
# yet the same, but ``pv`` should be a ``procvar``
macro x3*: untyped =
result = quote do:
`pv`()
# all ``x1``, ``x2`` and ``x3`` will call ``a.p``/``a.pv``, wherever called
# ``p`` is always unbound
macro y1*: untyped =
result = newNimNode(nnkStmtList)
result.add newCall("p")
# ``p`` is bound, just because *a* is imported, would be unbound otherwise
macro y2*: untyped =
result = quote do:
p()
# ``p`` is explicitly unbound
template y3* =
mixin p
p()
# module c
# the main module for the example
import b
x1() # -> p of a
x2() # -> p of a
x3() # -> pv of a
import a
y1() # -> p of a
y2() # -> p of a
y3() # -> p of a
# module c2
import b
x1() # -> p of a
x2() # -> p of a
x3() # -> pv of a
import a2
y1() # -> p of a2
y2() # -> p of a
#y3() # won't compile, both ``p`` from *a* and *a2* match;
# removing ``mixin`` in ``y3`` will make this print "p of a"