public object Run(IFn func) { var p = ClojureInit.Eval.invoke(Clojure.read("(promise)")); Run(() => { ClojureInit.Sync.invoke(func, this.app.ActiveUIDocument, p); }); return(p); }
static ClojureInit() { Eval = Clojure.var("clojure.core", "eval"); object execFn = Clojure.read(@" (defn execute ""evaluates s-forms"" ([request](execute request *ns*)) ([request user-ns] (try (binding [*ns* user-ns] (eval (read-string request))) (catch Exception e (str (. e Message) "" "" (. e StackTrace ))) )))"); object nsGenFn = Clojure.read(@" (defn generate-ns ""generates ns for client connection"" [] (let [user-ns (create-ns (symbol(str ""user"" )))] (execute(str ""(clojure.core/refer 'clojure.core)"") user-ns) user-ns)) "); //object definer = Clojure.read("(fn [name data] (def (symbol name) data ) ) "); //DefinerFn = Eval.invoke(definer) as IFn; var SyncCode = Clojure.read("(fn [handler document prom] (deliver prom (try (handler document) (catch Exception e e)) ) ) "); Eval.invoke(Clojure.read("(def ^:dynamic sync)")); Sync = Eval.invoke(SyncCode) as IFn; var replCode = Clojure.read("(fn [in out err synchronizer] (binding [*in* in, *out* out *err* err sync synchronizer] (clojure.main/with-bindings (loop [] (try (clojure.main/repl ) (catch Exception e (clojure.main/repl-caught e) (set! *e e))) (flush) (recur)) ) ))"); repl = Eval.invoke(replCode) as IFn; ExecuteInNs = Eval.invoke(execFn) as IFn; nsGen = Eval.invoke(nsGenFn) as IFn; NS = nsGen.invoke(); ExecuteInNs.invoke("(use \'clojure.reflect \'clojure.pprint \'clojure.repl)", NS); //ReplExe = ExecuteInNs.invoke(" (defn print-exe [r] (with-out-str (clojure.pprint/pprint (clojure.core/execute r)))") as IFn; }
public Result OnStartup(UIControlledApplication application) { execute = eval.invoke(execFn) as IFn; nsGen = eval.invoke(nsGenFn) as IFn; ns = nsGen.invoke(); application.ControlledApplication.DocumentOpened += (sender, args) => { execute.invoke( Clojure.read(" (def config {:port 9998 :name (name (gensym)) :accept 'clojure.core.server/repl }) "), ns); execute.invoke(Clojure.read(" (def server (clojure.core.server/start-server config)) "), ns); }; execute.invoke( Clojure.read(" (def config {:port 9998 :name (name (gensym)) :accept 'clojure.core.server/repl }) "), ns); server = execute.invoke(Clojure.read(" (def server (clojure.core.server/start-server config)) "), ns); return(Result.Succeeded); }
public object Run(IFn func) { var p = ClojureInit.Eval.invoke(Clojure.read("(promise)")); return(ClojureInit.Sync.invoke(func, document, p)); }