I have the following macro that calls a reflect function in a module.  The 
reflect function generates functions according to information passed back 
from a server.  The problem is that those functions only exist in that 
module's namespace.  I want them to exist in the calling namespace, so I'm 
trying to use another macro.  In the loadlib macro, I have everything 
working except for the @eval line.  I want the 'name' symbols to expand to 
what is in the 'name' variable before the evaluation takes place, but I 
just can't figure out the syntax.

macro loadlib(s, library)
   quote 
      funcs = reflect($(esc(s)), library=$(esc(library)))
      for v in values(funcs)
         if isa(v, Dict) && haskey(v, "name")
            name = symbol(v["name"])
            @eval name = getfield(libname, name)
         end
      end
   end
end

macroexpand(:(@loadlib(s, "foo")))

quote  # In[70], line 3:
    #8231#funcs = reflect(s,library="foo") # line 4:
    for #8232#v = values(#8231#funcs) # line 5:
        if isa(#8232#v,Dict) && haskey(#8232#v,"name") # line 6:
            #8233#name = symbol(#8232#v["name"]) # line 7:
            eval($(Expr(:copyast, :(#8233#name = 
getfield(libname,#8233#name))))) # line 8:
        end
    end
end

Reply via email to