@@ -111,13 +111,16 @@ m_eval(expr) = m_eval(cur_mod(), expr)
111111 * develop! <names...> # Add functions that are part of the development API (extendible)
112112 * modules <names...> # Add submodule names that are part of the API
113113
114+ * path <paths...> # Add paths to LOAD_PATH
115+
114116 * def <name> <expr> # Same as the @def macro, creates a macro with the given name
115117
116118"""
117119macro api (cmd:: Symbol )
118120 mod = @static V6_COMPAT ? current_module () : @__MODULE__
119121 cmd == :list ? _api_list (mod) :
120122 cmd == :freeze ? _api_freeze (mod) :
123+ cmd == :test ? _api_test (mod) :
121124 error (" @api unrecognized command: $cmd " )
122125end
123126
@@ -132,6 +135,20 @@ function _api_freeze(mod::Module)
132135 nothing
133136end
134137
138+ function _api_path (curmod, exprs)
139+ for exp in exprs
140+ if isa (exp, Expr) || isa (exp, Symbol)
141+ str = m_eval (curmod, exp)
142+ elseif isa (exp, String)
143+ str = exp
144+ else
145+ error (" @api path: syntax error $exp " )
146+ end
147+ m_eval (curmod, :( push! (LOAD_PATH , $ str) ))
148+ end
149+ nothing
150+ end
151+
135152const _cmduse = (:use , :use! , :test , :extend , :extend! , :export , :list )
136153const _cmdadd =
137154 (:modules , :public , :develop , :public! , :develop! , :base , :base! )
@@ -276,15 +293,22 @@ function _api_list(curmod, modules)
276293 nothing
277294end
278295
296+ _api_test (mod) = m_eval (mod, V6_COMPAT ? :(using Base. Test) : :(using Test))
297+
279298function _api (curmod:: Module , cmd:: Symbol , exprs)
280299 cmd == :def && return _api_def (exprs... )
300+ cmd == :path && return _api_path (curmod, exprs)
281301
282302 ind = _ff (_cmdadd, cmd)
283303 ind == 0 || return _add_symbols (curmod, cmd, exprs)
284304
285305 _ff (_cmduse, cmd) == 0 && error (" Syntax error: @api $cmd $exprs " )
286306
287307 debug[] && print (" _api($curmod , $cmd , $exprs )" )
308+
309+ # Be nice and set up standard Test
310+ cmd == :test && _api_test (curmod)
311+
288312 modules = SymSet ()
289313 for ex in exprs
290314 if isa (ex, Expr) && ex. head == :tuple
@@ -324,9 +348,6 @@ function _api(curmod::Module, cmd::Symbol, exprs)
324348 end
325349 end
326350
327- # Be nice and set up standard Test
328- cmd == :test && m_eval (curmod, V6_COMPAT ? :(using Base. Test) : :(using Test))
329-
330351 cpy = (cmd == :use! ) || (cmd == :extend! )
331352
332353 cpy && _init_api (curmod)
0 commit comments