[#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,
|
||||
"allPublicConstructors" : true
|
||||
}, {
|
||||
"allPublicConstructors" : true,
|
||||
"methods" : [ {
|
||||
"name" : "activeCount"
|
||||
}, {
|
||||
|
|
|
|||
|
|
@ -65,9 +65,10 @@
|
|||
sun.nio.fs.UnixPath ;; included because of permission check
|
||||
]
|
||||
:custom-classes {'java.lang.Thread
|
||||
;; generated with `public-declared-method-names`, see in
|
||||
;; `comment` below
|
||||
{:methods [{:name "activeCount"}
|
||||
{:allPublicConstructors true
|
||||
;; generated with `public-declared-method-names`, see in
|
||||
;; `comment` below
|
||||
:methods [{:name "activeCount"}
|
||||
{:name "checkAccess"}
|
||||
{:name "currentThread"}
|
||||
{:name "dumpStack"}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
(ns babashka.impl.utils
|
||||
{: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]
|
||||
(sci/with-bindings {sci/out *out*
|
||||
sci/in *in*
|
||||
sci/err *err*}
|
||||
(sci/eval-string expr ctx)))
|
||||
(sci/eval-string expr ctx))
|
||||
|
|
|
|||
|
|
@ -308,8 +308,11 @@
|
|||
(is (= "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
|
||||
|
||||
(comment
|
||||
(dotimes [i 10] (wait-for-port-test))
|
||||
(dotimes [_ 10] (wait-for-port-test))
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
(:require
|
||||
[babashka.main :as main]
|
||||
[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)
|
||||
|
||||
|
|
@ -14,17 +15,25 @@
|
|||
bindings-map (cond-> {sci/out os
|
||||
sci/err es}
|
||||
is (assoc sci/in is))]
|
||||
(sci/with-bindings bindings-map
|
||||
(let [res (binding [*out* os
|
||||
*err* es]
|
||||
(if input
|
||||
(with-in-str input (apply main/main args))
|
||||
(apply main/main args)))]
|
||||
(if (zero? res)
|
||||
(str os)
|
||||
(throw (ex-info (str es)
|
||||
{:stdout (str os)
|
||||
:stderr (str es)})))))))
|
||||
(try
|
||||
(when input (vars/bindRoot sci/in is))
|
||||
(vars/bindRoot sci/out os)
|
||||
(vars/bindRoot sci/err es)
|
||||
(sci/with-bindings bindings-map
|
||||
(let [res (binding [*out* os
|
||||
*err* es]
|
||||
(if input
|
||||
(with-in-str input (apply main/main args))
|
||||
(apply main/main args)))]
|
||||
(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]
|
||||
(let-programs [bb "./bb"]
|
||||
|
|
|
|||
Loading…
Reference in a new issue