You could do it by wrapping in a template
import macros
template foo(body: untyped) =
block:
let inFoo {. inject, used .} = true
body
template bar(body: untyped) =
block:
let inBar {. inject, used .} = true
body
proc callApiFromFoo =
echo "Calling API with foo scope"
proc callApiFromBar =
echo "Calling API with bar scope"
template callApi =
when declaredInScope(inFoo):
callApiFromFoo()
elif declaredInScope(inBar):
callApiFromBar()
else:
echo "You can call API only in foo or bar scopes!"
proc foobar =
foo:
callApi()
bar:
callApi()
foobar()
Run
- Is it possible for a macro to know the context it is used? spip
- Re: Is it possible for a macro to know the context it is use... dawkot
- Re: Is it possible for a macro to know the context it is... spip
- Re: Is it possible for a macro to know the context i... dawkot
- Re: Is it possible for a macro to know the conte... spip
- Re: Is it possible for a macro to know the ... Araq
- Re: Is it possible for a macro to know ... spip
- Re: Is it possible for a macro to k... spip
- Re: Is it possible for a macro to k... jcosborn
- Re: Is it possible for a macro to k... spip
- Re: Is it possible for a macro to k... jcosborn
