Is it possible to get the fieldnames of a struct inside a macro?

julia> macro doit(T)
           fnames = fieldnames(eval(T))
           # better:
           # fieldnames(Core.eval(__module__, T))
           @show fnames
       end
@doit (macro with 1 method)

julia> struct S;a;b;end

julia> @doit S
fnames = (:a, :b)
(:a, :b)

See also Using eval inside macro? - #2 by yuyichao

2 Likes