This commit is contained in:
Michiel Borkent 2021-05-26 14:03:53 +02:00
parent 3e3db8ed6d
commit 97369859dd

View file

@ -1,11 +1,10 @@
(ns scittle.core (ns scittle.core
(:refer-clojure :exclude [defn time]) (:refer-clojure :exclude [time])
(:require [clojure.core :as c] (:require [goog.object :as gobject]
[goog.object :as gobject]
[goog.string] [goog.string]
[sci.core :as sci])) [sci.core :as sci]))
(c/defmacro time (defmacro time
"Evaluates expr and prints the time it took. Returns the value of expr." "Evaluates expr and prints the time it took. Returns the value of expr."
[expr] [expr]
`(let [start# (cljs.core/system-time) `(let [start# (cljs.core/system-time)
@ -29,14 +28,14 @@
:classes {'js js/window :classes {'js js/window
:allow :all}}))) :allow :all}})))
(c/defn ^:export eval-string [s] (defn ^:export eval-string [s]
(sci/eval-string* @ctx s)) (sci/eval-string* @ctx s))
(c/defn register-plugin! [plug-in-name sci-opts] (defn register-plugin! [plug-in-name sci-opts]
plug-in-name ;; unused for now plug-in-name ;; unused for now
(swap! ctx sci/merge-opts sci-opts)) (swap! ctx sci/merge-opts sci-opts))
(c/defn- load-contents [script-tags] (defn load-contents [script-tags]
(when-let [tag (first script-tags)] (when-let [tag (first script-tags)]
(if-let [text (not-empty (gobject/get tag "textContent"))] (if-let [text (not-empty (gobject/get tag "textContent"))]
(do (eval-string text) (do (eval-string text)