# Registering information to a module global dict using macros

**URL:** <https://discourse.julialang.org/t/registering-information-to-a-module-global-dict-using-macros/77766>\
**Category:** General Usage\
**Created:** [March 11, 2022, 6:54pm UTC](https://discourse.julialang.org/t/registering-information-to-a-module-global-dict-using-macros/77766 "2022-03-11T18:54:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkschleg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkschleg/32/8035_2.png) [@mkschleg](https://discourse.julialang.org/u/mkschleg)\
**Post date:** [March 11, 2022, 6:54pm UTC](https://discourse.julialang.org/t/registering-information-to-a-module-global-dict-using-macros/77766/1 "2022-03-11T18:54:04Z")

</div>

Hello! I’m trying to get some convenience functionality working for a macro I’m working on. What I want to do is register a key and where this key occurs in both the internal package and external uses of the package. You can see the MWE below and what I’m seeing with different use cases. The documentation mentions this in the Module section + precompilation, but doesn’t give any details on how to accomplish this (afaict).

Ok. It needs to be a bit more complex to get the behaviour I’m seeing. In a package called MWE:

MWE/src/MWE.jl

```julia
module MWE

import Logging
const StrgDict = Dict{String, LineNumberNode}()

macro data(msg, exs...)
    StrgDict[msg] = __source__
    :($Logging.@info $msg $(exs...)) |> esc
end

function my_func(j)
    @data "Internal" j
end

end # module

```

MWE/ext/MyModule.jl

```julia
module MyModule
import MWE

function my_func()

    MWE.@data "Hello" x=1
end

function another_func(q)
    MWE.@data "Goodby" q
end

end

```

Then in a julia session w/ the project activated and ext added to the load path:

import:

```julia
julia> import MyModule
[Info: Precompiling MyModule [top-level]

julia> MyModule.MWE.StrgDict
Dict{String, LineNumberNode} with 1 entry:
  "Internal" => :(#= /Users/Matt/Documents/Developer_Projects/JuliaDev/MWE/src/MWE.jl:13 =#)

```

include:

```julia
julia> include("ext/MyModule.jl")
[Info: Precompiling MWE [02cddd85-a227-493d-88c6-f170f361fb05]
Main.MyModule

julia> MyModule.MWE.StrgDict
Dict{String, LineNumberNode} with 3 entries:
  "Internal" => :(#= /Users/Matt/Documents/Developer_Projects/JuliaDev/MWE/src/MWE.jl:13 =#)
  "Hello" => :(#= /Users/Matt/Documents/Developer_Projects/JuliaDev/MWE/ext/MyModule.jl:7 =#)
  "Goodby" => :(#= /Users/Matt/Documents/Developer_Projects/JuliaDev/MWE/ext/MyModule.jl:13 =#)

```

---

<div class="post-metadata">

**Author:** ![mkschleg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkschleg/32/8035_2.png) [@mkschleg](https://discourse.julialang.org/u/mkschleg)\
**Post date:** [April 6, 2022, 4:44pm UTC](https://discourse.julialang.org/t/registering-information-to-a-module-global-dict-using-macros/77766/2 "2022-04-06T16:44:07Z")

</div>

For those coming here. The only solution is to have a storage solution in the module you are wanting to register things in and then call a registering function in your **init**. You can see this in the `Automatic registering` section and the ExampleProject of this repo: [https://github.com/mkschleg/ChoosyDataLoggers.jl](https://github.com/mkschleg/ChoosyDataLoggers.jl). So far, I don’t think there is another more automatic way to do this.
