How to get current module/scope in macro

Hi, community.

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

Just like this:

module SomeModule
macro f()
    S =  caller_module.eval(:S)
    fields = fieldnames(S)
   # do something with fields
end
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?

__module__, which is how @__MODULE__ is implemented

3 Likes

Thanks .
__module__ is exactly what I want.