[#159] set sci var roots to *in*, *out* and *err*
This commit is contained in:
parent
a9231b7ecf
commit
4f488ca684
5 changed files with 38 additions and 21 deletions
|
|
@ -294,6 +294,7 @@
|
||||||
"allPublicFields" : true,
|
"allPublicFields" : true,
|
||||||
"allPublicConstructors" : true
|
"allPublicConstructors" : true
|
||||||
}, {
|
}, {
|
||||||
|
"allPublicConstructors" : true,
|
||||||
"methods" : [ {
|
"methods" : [ {
|
||||||
"name" : "activeCount"
|
"name" : "activeCount"
|
||||||
}, {
|
}, {
|
||||||
|
|
|
||||||
|
|
@ -65,9 +65,10 @@
|
||||||
sun.nio.fs.UnixPath ;; included because of permission check
|
sun.nio.fs.UnixPath ;; included because of permission check
|
||||||
]
|
]
|
||||||
:custom-classes {'java.lang.Thread
|
:custom-classes {'java.lang.Thread
|
||||||
;; generated with `public-declared-method-names`, see in
|
{:allPublicConstructors true
|
||||||
;; `comment` below
|
;; generated with `public-declared-method-names`, see in
|
||||||
{:methods [{:name "activeCount"}
|
;; `comment` below
|
||||||
|
:methods [{:name "activeCount"}
|
||||||
{:name "checkAccess"}
|
{:name "checkAccess"}
|
||||||
{:name "currentThread"}
|
{:name "currentThread"}
|
||||||
{:name "dumpStack"}
|
{:name "dumpStack"}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
(ns babashka.impl.utils
|
(ns babashka.impl.utils
|
||||||
{:no-doc true}
|
{:no-doc true}
|
||||||
(:require [sci.core :as sci]))
|
(:require
|
||||||
|
[sci.impl.vars :as vars]
|
||||||
|
[sci.core :as sci]))
|
||||||
|
|
||||||
|
(sci.impl.vars/bindRoot sci/in *in*)
|
||||||
|
(sci.impl.vars/bindRoot sci/out *out*)
|
||||||
|
(sci.impl.vars/bindRoot sci/err *err*)
|
||||||
|
|
||||||
(defn eval-string [expr ctx]
|
(defn eval-string [expr ctx]
|
||||||
(sci/with-bindings {sci/out *out*
|
(sci/eval-string expr ctx))
|
||||||
sci/in *in*
|
|
||||||
sci/err *err*}
|
|
||||||
(sci/eval-string expr ctx)))
|
|
||||||
|
|
|
||||||
|
|
@ -308,8 +308,11 @@
|
||||||
(is (= "babashka"
|
(is (= "babashka"
|
||||||
(bb nil "(String. (.decode (java.util.Base64/getDecoder) (.encode (java.util.Base64/getEncoder) (.getBytes \"babashka\"))))"))))
|
(bb nil "(String. (.decode (java.util.Base64/getDecoder) (.encode (java.util.Base64/getEncoder) (.getBytes \"babashka\"))))"))))
|
||||||
|
|
||||||
|
(deftest Thread-test
|
||||||
|
(is (= "hello" (bb nil "(doto (java.lang.Thread. (fn [] (prn \"hello\"))) (.start) (.join)) nil"))))
|
||||||
|
|
||||||
;;;; Scratch
|
;;;; Scratch
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(dotimes [i 10] (wait-for-port-test))
|
(dotimes [_ 10] (wait-for-port-test))
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
(:require
|
(:require
|
||||||
[babashka.main :as main]
|
[babashka.main :as main]
|
||||||
[me.raynes.conch :refer [let-programs] :as sh]
|
[me.raynes.conch :refer [let-programs] :as sh]
|
||||||
[sci.core :as sci]))
|
[sci.core :as sci]
|
||||||
|
[sci.impl.vars :as vars]))
|
||||||
|
|
||||||
(set! *warn-on-reflection* true)
|
(set! *warn-on-reflection* true)
|
||||||
|
|
||||||
|
|
@ -14,17 +15,25 @@
|
||||||
bindings-map (cond-> {sci/out os
|
bindings-map (cond-> {sci/out os
|
||||||
sci/err es}
|
sci/err es}
|
||||||
is (assoc sci/in is))]
|
is (assoc sci/in is))]
|
||||||
(sci/with-bindings bindings-map
|
(try
|
||||||
(let [res (binding [*out* os
|
(when input (vars/bindRoot sci/in is))
|
||||||
*err* es]
|
(vars/bindRoot sci/out os)
|
||||||
(if input
|
(vars/bindRoot sci/err es)
|
||||||
(with-in-str input (apply main/main args))
|
(sci/with-bindings bindings-map
|
||||||
(apply main/main args)))]
|
(let [res (binding [*out* os
|
||||||
(if (zero? res)
|
*err* es]
|
||||||
(str os)
|
(if input
|
||||||
(throw (ex-info (str es)
|
(with-in-str input (apply main/main args))
|
||||||
{:stdout (str os)
|
(apply main/main args)))]
|
||||||
:stderr (str es)})))))))
|
(if (zero? res)
|
||||||
|
(str os)
|
||||||
|
(throw (ex-info (str es)
|
||||||
|
{:stdout (str os)
|
||||||
|
:stderr (str es)})))))
|
||||||
|
(finally
|
||||||
|
(when input (vars/bindRoot sci/in *in*))
|
||||||
|
(vars/bindRoot sci/out *out*)
|
||||||
|
(vars/bindRoot sci/err *err*)))))
|
||||||
|
|
||||||
(defn bb-native [input & args]
|
(defn bb-native [input & args]
|
||||||
(let-programs [bb "./bb"]
|
(let-programs [bb "./bb"]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue