# How to get current module/scope in macro

**URL:** <https://discourse.julialang.org/t/how-to-get-current-module-scope-in-macro/13310>\
**Category:** General Usage\
**Tags:** module, scope\
**Created:** [August 12, 2018, 4:36pm UTC](https://discourse.julialang.org/t/how-to-get-current-module-scope-in-macro/13310 "2018-08-12T16:36:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thautwarm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thautwarm/32/37760_2.png) [@thautwarm](https://discourse.julialang.org/u/thautwarm)\
**Post date:** [August 12, 2018, 4:36pm UTC](https://discourse.julialang.org/t/how-to-get-current-module-scope-in-macro/13310/1 "2018-08-12T16:36:32Z")

</div>

Hi, community.

Could I get the module or scope of the calller of macro in Julia1.0?

Just like this:

```julia
module SomeModule
macro f()
    S = caller_module.eval(:S)
    fields = fieldnames(S)
   # do something with fields
end

```

```julia
module OtherModule
import SomeModule: @f 
struct S 
    ...
end
function fn(...)
   let staged_analysis = @f
      # do stuff 
  end
end

```

I do know that I can return an escaped macro and it works well in runtime(after macro application and when calling function), however, I might not be able to be use metadata of types and such stuffs when compiling callers of macro(when applying macro).

P.S: `@ __MODULE__ ` returns macro callee’s scope, so it’s not what I want.

Any helps, please?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [August 12, 2018, 4:46pm UTC](https://discourse.julialang.org/t/how-to-get-current-module-scope-in-macro/13310/2 "2018-08-12T16:46:31Z")

</div>

` __module__ `, which is how `@ __MODULE__ ` is implemented

---

<div class="post-metadata">

**Author:** ![thautwarm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thautwarm/32/37760_2.png) [@thautwarm](https://discourse.julialang.org/u/thautwarm)\
**Post date:** [August 12, 2018, 4:53pm UTC](https://discourse.julialang.org/t/how-to-get-current-module-scope-in-macro/13310/3 "2018-08-12T16:53:34Z")

</div>

Thanks .  
` __module__ ` is exactly what I want.
