Skip to content

Commit

Permalink
Add @reexport macro
Browse files Browse the repository at this point in the history
Syntax is:

@reexport using MyModule1, MyModule2

Fixes #1986
  • Loading branch information
simonster committed Jan 30, 2014
1 parent f384033 commit a8e43d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1296,4 +1296,5 @@ export
@sprintf,
@deprecate,
@boundscheck,
@inbounds
@inbounds,
@reexport
12 changes: 12 additions & 0 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,15 @@ function evalfile(path::String, args::Vector{UTF8String}=UTF8String[])
:(include($path))))
end
evalfile(path::String, args::Vector) = evalfile(path, UTF8String[args...])

macro reexport(ex)
(isa(ex, Expr) && ex.head == :toplevel && begin
valid = true
for usingex in ex.args
valid &= isa(usingex, Expr) && usingex.head == :using
end
valid
end) || error("@reexport: syntax error")
esc(Expr(:toplevel, ex.args...,
[:(eval(Expr(:export, names($(usingex.args[end]))...))) for usingex in ex.args]...))
end

0 comments on commit a8e43d8

Please sign in to comment.