diff options
author | David Barksdale <amatus.amongus@gmail.com> | 2011-02-02 15:30:01 -0800 |
---|---|---|
committer | David Barksdale <amatus.amongus@gmail.com> | 2011-02-02 15:41:46 -0800 |
commit | 85a92c0112e74709c08a168c802cee05fd9198b4 (patch) | |
tree | 049c4545bc324e7e57a1637b2b6d822a7dc3ab4c | |
parent | eb0f5a92ba8ea99161d6682e20f86accc51b4fd6 (diff) |
Created gen-class :set-context-classloader.
Fixed ProtectionDomain on compiled classes.
The applet repl is now in the applet's namespace.
Created *applet* so the repl can refer to the applet.
Renamed in to write, IE8 didn't like "in".
-rw-r--r-- | clojure-1.2.0.jar | bin | 3237334 -> 3237601 bytes | |||
-rw-r--r-- | src/org/gnu/clojure/gnunetapplet/applet.clj | 76 |
2 files changed, 40 insertions, 36 deletions
diff --git a/clojure-1.2.0.jar b/clojure-1.2.0.jar Binary files differindex be97e00..b067bb0 100644 --- a/clojure-1.2.0.jar +++ b/clojure-1.2.0.jar diff --git a/src/org/gnu/clojure/gnunetapplet/applet.clj b/src/org/gnu/clojure/gnunetapplet/applet.clj index aa45ff8..86e9b80 100644 --- a/src/org/gnu/clojure/gnunetapplet/applet.clj +++ b/src/org/gnu/clojure/gnunetapplet/applet.clj @@ -1,10 +1,10 @@ (ns org.gnu.clojure.gnunetapplet.applet - (:use (org.gnu.clojure.gnunet crypto exception) - clojure.contrib.monads) - (:use [clojure.main :only (repl)]) + (:use clojure.contrib.monads + [clojure.main :only (repl)] + (org.gnu.clojure.gnunet crypto exception)) (:import clojure.lang.LineNumberingPushbackReader - (java.io ByteArrayOutputStream InputStreamReader OutputStreamWriter + (java.io InputStreamReader OutputStreamWriter PipedInputStream PipedOutputStream PrintWriter) (netscape.javascript JSObject JSException)) (:gen-class @@ -12,8 +12,11 @@ :state state :init ctor :main false + :set-context-classloader true :methods [[ver [] String] - [in [String] Void]])) + [write [String] Void]])) + +(def applet-ns *ns*) (defn -ctor "The job of this constructor is to initialize state. The rest of the @@ -21,51 +24,52 @@ [] [[] (agent {})]) +(defn jscall + [applet f & args] + (try + (.call (JSObject/getWindow applet) f (object-array args)) + (catch JSException e + (.printStackTrace e)))) + (defn my-repl [applet] (.setContextClassLoader (Thread/currentThread) (.getClassLoader (.getClass applet))) (let [input (PipedOutputStream.) - stdin (LineNumberingPushbackReader. - (InputStreamReader. - (PipedInputStream. input))) - stdout (OutputStreamWriter. - (proxy [ByteArrayOutputStream] [] - (flush [] - (let [output (str this)] - (.reset this) - (try - (.call (JSObject/getWindow applet) - "out" (object-array [output])) - (catch JSException e nil)))))) - stderr (PrintWriter. - (OutputStreamWriter. - (proxy [ByteArrayOutputStream] [] - (flush [] - (let [output (str this)] - (.reset this) - (try - (.call (JSObject/getWindow applet) - "err" (object-array [output])) - (catch JSException e nil)))))))] - (send (.state applet) - (fn [state] - (assoc state :input input))) - (with-bindings {#'*in* stdin #'*out* stdout #'*err* stderr} (repl)))) + in (LineNumberingPushbackReader. + (InputStreamReader. (PipedInputStream. input))) + out (OutputStreamWriter. + (proxy [java.io.ByteArrayOutputStream] [] + (flush [] + (jscall applet "out" (str this)) + (.reset this)))) + err (PrintWriter. + (OutputStreamWriter. + (proxy [java.io.ByteArrayOutputStream] [] + (flush [] + (jscall applet "err" (str this)) + (.reset this)))) + true)] + (send (.state applet) #(assoc % :input input)) + (declare *applet*) + (with-bindings {#'*in* in + #'*out* out + #'*err* err + #'*ns* applet-ns + #'*applet* applet} + (repl)))) (defn -init [this] (let [thread (Thread. (partial my-repl this))] (.start thread) - (send (.state this) - (fn [state] - (assoc state :repl-thread thread))))) + (send (.state this) #(assoc % :repl-thread thread)))) (defn -ver [this] - "0.5") + "0.12") -(defn -in +(defn -write [this string] (when-let [input (:input (deref (.state this)))] (.write input (.getBytes string)))) |