|
14 | 14 | [sci.impl.callstack :as cs]
|
15 | 15 | [sci.impl.interpreter :as i]
|
16 | 16 | [sci.impl.io :as sio]
|
| 17 | + [sci.impl.load :as load] |
17 | 18 | [sci.impl.macros :as macros]
|
18 | 19 | [sci.impl.namespaces :as namespaces]
|
19 | 20 | [sci.impl.opts :as opts]
|
|
144 | 145 |
|
145 | 146 | ;; REPL variables
|
146 | 147 |
|
147 |
| - |
148 | 148 | (macros/deftime
|
149 | 149 | (defmacro with-in-str
|
150 | 150 | "Evaluates body in a context in which sci's *in* is bound to a fresh
|
|
359 | 359 | (let [publics (if exclude (apply dissoc publics exclude) publics)]
|
360 | 360 | publics))
|
361 | 361 |
|
362 |
| -(defn- exclude-when-meta [publics-map meta-fn key-fn val-fn skip-keys ] |
| 362 | +(defn- exclude-when-meta [publics-map meta-fn key-fn val-fn skip-keys] |
363 | 363 | (reduce (fn [ns-map [var-name var]]
|
364 | 364 | (if-let [m (meta-fn var)]
|
365 | 365 | (if (some m skip-keys)
|
|
371 | 371 |
|
372 | 372 | (defn- meta-fn [opts]
|
373 | 373 | (cond (= :all opts) identity
|
374 |
| - opts #(select-keys % opts) |
| 374 | + opts #(select-keys % opts) |
375 | 375 | :else #(select-keys % [:arglists
|
376 | 376 | :no-doc
|
377 | 377 | :macro
|
378 | 378 | :doc
|
379 | 379 | :dynamic])))
|
380 | 380 |
|
381 |
| - |
382 | 381 | (macros/deftime
|
383 | 382 | (defmacro copy-ns
|
384 | 383 | "Returns map of names to SCI vars as a result of copying public
|
|
462 | 461 | [:no-doc :skip-wiki]))]
|
463 | 462 | `(-copy-ns ~publics-map ~sci-ns)))))))
|
464 | 463 |
|
| 464 | +(defn add-import! |
| 465 | + "Adds import of class named by `class-name` (a symbol) to namespace named by `ns-name` (a symbol) under alias `alias` (a symbol). Returns mutated context." |
| 466 | + [ctx ns-name class-name alias] |
| 467 | + ;; This relies on an internal format of the context and may change at any time. |
| 468 | + (swap! (:env ctx) assoc-in [:namespaces ns-name :imports alias] class-name) |
| 469 | + ctx) |
| 470 | + |
465 | 471 | (defn add-class!
|
466 | 472 | "Adds class (JVM class or JS object) to `ctx` as `class-name` (a
|
467 | 473 | symbol). Returns mutated context."
|
|
474 | 480 | (assoc-in [:raw-classes class-name] class))))
|
475 | 481 | ctx))
|
476 | 482 |
|
477 |
| -(defn add-import! |
478 |
| - "Adds import of class named by `class-name` (a symbol) to namespace named by `ns-name` (a symbol) under alias `alias` (a symbol). Returns mutated context." |
479 |
| - [ctx ns-name class-name alias] |
480 |
| - ;; This relies on an internal format of the context and may change at any time. |
481 |
| - (swap! (:env ctx) assoc-in [:namespaces ns-name :imports alias] class-name) |
482 |
| - ctx) |
483 |
| - |
484 | 483 | (defn add-namespace!
|
485 | 484 | "Adds namespace map `ns-map` named by the symbol `ns-name` to
|
486 | 485 | `ctx`. Returns mutated context."
|
|
520 | 519 | (defn resolve [ctx sym]
|
521 | 520 | (@utils/eval-resolve-state ctx {} sym))
|
522 | 521 |
|
| 522 | +#?(:cljs |
| 523 | + (defn add-js-lib! |
| 524 | + "Add js library to context, so it can be used with `require`." |
| 525 | + [ctx name-str js-lib] |
| 526 | + (swap! (:env ctx) assoc-in [:js-libs name-str] js-lib) |
| 527 | + ctx)) |
| 528 | + |
523 | 529 | ;;;; Scratch
|
0 commit comments