Skip to content

Commit

Permalink
Added docstring support to @agent
Browse files Browse the repository at this point in the history
Fixes issue JuliaDynamics#715. With thanks to Michael Hatherly!
  • Loading branch information
veddox committed Dec 19, 2022
1 parent 6a8bbe5 commit 3bf40e3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/core/agents.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,18 @@ macro agent(new_name, base_type, extra_fields)
$(base_fields...)
$(additional_fields...)
end
#@doc @doc(name) $name # $docstring $name
end
# @show expr # uncomment this to see that the final expression looks as desired
# It is important to evaluate the macro in the module that it was called at
Core.eval($(__module__), expr)
end
# allow attaching docstrings to the new struct, issue #715
Core.@__doc__($(esc(Docs.namify(new_name))))
nothing
end
end


# TODO: I do not know how to merge these two macros to remove code duplication.
# There should be away that only the 4-argument version is used
# and the 3-argument version just passes `AbstractAgent` to the 4-argument.
Expand Down Expand Up @@ -232,8 +237,11 @@ macro agent(new_name, base_type, super_type, extra_fields)
end
# @show expr # uncomment this to see that the final expression looks as desired
# It is important to evaluate the macro in the module that it was called at
Core.eval($(__module__), expr)
Core.eval($(__module__), Core.@__doc__(expr))
end
# allow attaching docstrings to the new struct, issue #715
Core.@__doc__($(esc(Docs.namify(new_name))))
nothing
end
end

Expand Down

0 comments on commit 3bf40e3

Please sign in to comment.