Fix bug with *input* when used in code from classpath
This commit is contained in:
parent
b14d239ebb
commit
02f5a85db3
2 changed files with 21 additions and 22 deletions
2
sci
2
sci
|
|
@ -1 +1 @@
|
||||||
Subproject commit 17b14cae6260ad56a37fb3f46de16255ae90f9b8
|
Subproject commit e0d5313c02d5ac62bdb4311cf41b0d565b7b6d22
|
||||||
|
|
@ -202,10 +202,6 @@ Everything after that is bound to *command-line-args*."))
|
||||||
(str/replace x #"^#!.*" ""))
|
(str/replace x #"^#!.*" ""))
|
||||||
(throw (Exception. (str "File does not exist: " file))))))
|
(throw (Exception. (str "File does not exist: " file))))))
|
||||||
|
|
||||||
(defn read-edn []
|
|
||||||
(edn/read {;;:readers *data-readers*
|
|
||||||
:eof ::EOF} *in*))
|
|
||||||
|
|
||||||
(def reflection-var (sci/new-dynamic-var '*warn-on-reflection* false))
|
(def reflection-var (sci/new-dynamic-var '*warn-on-reflection* false))
|
||||||
|
|
||||||
(defn load-file* [sci-ctx f]
|
(defn load-file* [sci-ctx f]
|
||||||
|
|
@ -309,7 +305,8 @@ Everything after that is bound to *command-line-args*."))
|
||||||
::EOF
|
::EOF
|
||||||
(if stream?
|
(if stream?
|
||||||
(if shell-in (or (read-line) ::EOF)
|
(if shell-in (or (read-line) ::EOF)
|
||||||
(read-edn))
|
(edn/read {;;:readers *data-readers*
|
||||||
|
:eof ::EOF} *in*))
|
||||||
(delay (cond shell-in
|
(delay (cond shell-in
|
||||||
(shell-seq *in*)
|
(shell-seq *in*)
|
||||||
edn-in
|
edn-in
|
||||||
|
|
@ -366,16 +363,20 @@ Everything after that is bound to *command-line-args*."))
|
||||||
ctx (addons/future ctx)
|
ctx (addons/future ctx)
|
||||||
sci-ctx (sci-opts/init ctx)
|
sci-ctx (sci-opts/init ctx)
|
||||||
_ (vreset! common/ctx sci-ctx)
|
_ (vreset! common/ctx sci-ctx)
|
||||||
|
input-var (sci/new-dynamic-var '*input* nil)
|
||||||
_ (swap! (:env sci-ctx)
|
_ (swap! (:env sci-ctx)
|
||||||
(fn [env]
|
(fn [env]
|
||||||
(update-in env [:namespaces 'clojure.core] assoc
|
(update env :namespaces
|
||||||
'load-file #(load-file* sci-ctx %))))
|
(fn [namespaces] [:namespaces 'clojure.main 'repl]
|
||||||
_ (swap! (:env sci-ctx)
|
(-> namespaces
|
||||||
(fn [env]
|
(assoc-in ['clojure.core 'load-file] #(load-file* sci-ctx %))
|
||||||
(assoc-in env [:namespaces 'clojure.main 'repl]
|
(assoc-in ['clojure.main 'repl]
|
||||||
(fn [& opts]
|
(fn [& opts]
|
||||||
(let [opts (apply hash-map opts)]
|
(let [opts (apply hash-map opts)]
|
||||||
(repl/start-repl! sci-ctx opts))))))
|
(repl/start-repl! sci-ctx opts))))
|
||||||
|
(assoc-in ['user (with-meta '*input*
|
||||||
|
(when-not stream?
|
||||||
|
{:sci.impl/deref! true}))] input-var))))))
|
||||||
preloads (some-> (System/getenv "BABASHKA_PRELOADS") (str/trim))
|
preloads (some-> (System/getenv "BABASHKA_PRELOADS") (str/trim))
|
||||||
[expressions exit-code]
|
[expressions exit-code]
|
||||||
(cond expressions [expressions nil]
|
(cond expressions [expressions nil]
|
||||||
|
|
@ -405,15 +406,13 @@ Everything after that is bound to *command-line-args*."))
|
||||||
socket-repl [(start-socket-repl! socket-repl sci-ctx) 0]
|
socket-repl [(start-socket-repl! socket-repl sci-ctx) 0]
|
||||||
(not (str/blank? expression))
|
(not (str/blank? expression))
|
||||||
(try
|
(try
|
||||||
(loop [in (read-next *in*)]
|
(loop []
|
||||||
(let [_ (swap! env update-in [:namespaces 'user]
|
(let [in (read-next *in*)]
|
||||||
assoc (with-meta '*input*
|
|
||||||
(when-not stream?
|
|
||||||
{:sci.impl/deref! true}))
|
|
||||||
(sci/new-dynamic-var '*input* in))]
|
|
||||||
(if (identical? ::EOF in)
|
(if (identical? ::EOF in)
|
||||||
[nil 0] ;; done streaming
|
[nil 0] ;; done streaming
|
||||||
(let [res [(let [res (eval-string* sci-ctx expression)]
|
(let [res [(let [res
|
||||||
|
(sci/binding [input-var in]
|
||||||
|
(eval-string* sci-ctx expression))]
|
||||||
(when (some? res)
|
(when (some? res)
|
||||||
(if-let [pr-f (cond shell-out println
|
(if-let [pr-f (cond shell-out println
|
||||||
edn-out prn)]
|
edn-out prn)]
|
||||||
|
|
@ -424,7 +423,7 @@ Everything after that is bound to *command-line-args*."))
|
||||||
(pr-f res))
|
(pr-f res))
|
||||||
(prn res)))) 0]]
|
(prn res)))) 0]]
|
||||||
(if stream?
|
(if stream?
|
||||||
(recur (read-next *in*))
|
(recur)
|
||||||
res)))))
|
res)))))
|
||||||
(catch Throwable e
|
(catch Throwable e
|
||||||
(error-handler* e verbose?)))
|
(error-handler* e verbose?)))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue