diff --git a/sci b/sci index 8c8bc854..d44c5b79 160000 --- a/sci +++ b/sci @@ -1 +1 @@ -Subproject commit 8c8bc8548a608dd0387ef9a9c85352816e3600b8 +Subproject commit d44c5b792e572ad4f13afeb3abc957272a455fa9 diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 1eabc8f6..1c25c94f 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -44,6 +44,7 @@ [sci.core :as sci] [sci.impl.namespaces :as sci-namespaces] [sci.impl.unrestrict :refer [*unrestricted*]] + [sci.impl.utils :refer [ctx-fn]] [sci.impl.vars :as vars]) (:gen-class)) @@ -308,9 +309,15 @@ Use bb run --help to show this help output. 'start-server (fn [& args] (apply server/start-server @common/ctx args))}) +(def input-var (sci/new-dynamic-var '*input*)) + (def namespaces (cond-> - {'clojure.tools.cli tools-cli-namespace + {'user {'*input* (ctx-fn + (fn [_ctx] + (force @input-var)) + nil)} + 'clojure.tools.cli tools-cli-namespace 'clojure.java.shell shell-namespace 'babashka.wait {'wait-for-port wait/wait-for-port 'wait-for-path wait/wait-for-path} @@ -433,7 +440,6 @@ Use bb run --help to show this help output. Thread java.lang.Thread Throwable java.lang.Throwable}) -(def input-var (sci/new-dynamic-var '*input* nil)) (def edn-readers (cond-> {} features/yaml? (assoc 'ordered/map @(resolve 'flatland.ordered.map/ordered-map)))) @@ -716,10 +722,7 @@ Use bb run --help to show this help output. :namespaces (-> namespaces (assoc 'clojure.core (assoc core-extras - 'load-file load-file*)) - (assoc-in ['user (with-meta '*input* - (when-not stream? - {:sci.impl/deref! true}))] input-var)) + 'load-file load-file*))) :env env :features #{:bb :clj} :classes classes/class-map diff --git a/test/babashka/main_test.clj b/test/babashka/main_test.clj index 7c38d419..2103a9e9 100644 --- a/test/babashka/main_test.clj +++ b/test/babashka/main_test.clj @@ -388,8 +388,7 @@ (is (= "hello" (bb nil "(doto (java.lang.Thread. (fn [] (prn \"hello\"))) (.start) (.join)) nil")))) (deftest dynvar-test - (is (= 1 (bb nil "(binding [*command-line-args* 1] *command-line-args*)"))) - (is (= 1 (bb nil "(binding [*input* 1] *input*)")))) + (is (= 1 (bb nil "(binding [*command-line-args* 1] *command-line-args*)")))) (deftest file-in-error-msg-test (is (thrown-with-msg? Exception #"error.bb"