Skip to content

Commit

Permalink
Merge pull request #5 from jackrusher/sci-context
Browse files Browse the repository at this point in the history
SCI: context
  • Loading branch information
jackrusher authored Mar 21, 2023
2 parents e34f5a3 + 50d3ab6 commit 1bd69d3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
17 changes: 12 additions & 5 deletions clj/src/com/rusher/scimacs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
(:require [sci.core :as sci])
(:gen-class :methods [^{:static true} [evalString [String] String]]))

(set! *warn-on-reflection* true)

(sci/alter-var-root sci/out (constantly *out*)) ;; enable println, etc.
(sci/alter-var-root sci/err (constantly *err*)) ;; enable println, etc.

(def ctx (sci/init {:namespaces {}
:classes {}}))

(defn -evalString [s]
(sci/binding [sci/out *out*] ; enable println, etc.
(str (try (sci/eval-string s)
(catch Exception e
{:error (str (type e))
:message (.getMessage e)})))))
(try (pr-str (sci/eval-string* ctx s))
(catch Exception e
(pr-str {:error (str (type e))
:message (.getMessage e)}))))

;; as second arg to eval-string, this binds a cheshire.core function within sci
#_{:namespaces {'cheshire.core {'generate-string cheshire/generate-string}}}
3 changes: 3 additions & 0 deletions test.el
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@
"(reduce + (range 5))")))
(message "Could not find loadable module!"))

(scimacs-eval-sci "(defn foo [x] (inc x))")
;; foo is still defined in the following call:
(scimacs-eval-sci "(foo 1)")

0 comments on commit 1bd69d3

Please sign in to comment.