How to get current module/scope in macro

module
scope

#1

Hi, community.

Could I get the module or scope of the calller of macro in Julia 1.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 call function), however, I might not be able to be use metadata of types and such stuffs when compiling callers of macro(when applying macro).

Any helps, please?


#2

Sorry for the double-post by mistakes. The first one is here.

I cannot delete this duplicated one, and thanks a lot if anyone helps me with it.