summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Barksdale <amatus.amongus@gmail.com>2011-01-30 02:05:30 -0800
committerDavid Barksdale <amatus.amongus@gmail.com>2011-02-02 15:40:50 -0800
commiteb0f5a92ba8ea99161d6682e20f86accc51b4fd6 (patch)
tree32b0a367fba23c6bbf689fa08d4d2b12a7a0323d
parent8aa9759e4d1647b2c1adc1531734bda96e45e839 (diff)
GNUnet applet created.
The clojure-1.2.0.jar contains a hack to fix the ContextClassLoader.
-rw-r--r--.classpath3
-rw-r--r--clojure-1.2.0.jar (renamed from clojure.jar)bin3237168 -> 3237334 bytes
-rw-r--r--src/org/gnu/clojure/gnunetapplet/applet.clj71
3 files changed, 73 insertions, 1 deletions
diff --git a/.classpath b/.classpath
index af8307c..b5825d2 100644
--- a/.classpath
+++ b/.classpath
@@ -2,8 +2,9 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="lib" path="/usr/lib/jvm/java-6-openjdk/jre/lib/plugin.jar"/>
<classpathentry kind="lib" path="classes"/>
- <classpathentry kind="lib" path="clojure.jar"/>
+ <classpathentry kind="lib" path="clojure-1.2.0.jar"/>
<classpathentry kind="lib" path="monads-1.3.0-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="accumulators-1.3.0-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="def-1.3.0-SNAPSHOT.jar"/>
diff --git a/clojure.jar b/clojure-1.2.0.jar
index 82b549d..be97e00 100644
--- a/clojure.jar
+++ b/clojure-1.2.0.jar
Binary files differ
diff --git a/src/org/gnu/clojure/gnunetapplet/applet.clj b/src/org/gnu/clojure/gnunetapplet/applet.clj
new file mode 100644
index 0000000..aa45ff8
--- /dev/null
+++ b/src/org/gnu/clojure/gnunetapplet/applet.clj
@@ -0,0 +1,71 @@
+(ns org.gnu.clojure.gnunetapplet.applet
+ (:use (org.gnu.clojure.gnunet crypto exception)
+ clojure.contrib.monads)
+ (:use [clojure.main :only (repl)])
+ (:import
+ clojure.lang.LineNumberingPushbackReader
+ (java.io ByteArrayOutputStream InputStreamReader OutputStreamWriter
+ PipedInputStream PipedOutputStream PrintWriter)
+ (netscape.javascript JSObject JSException))
+ (:gen-class
+ :extends java.applet.Applet
+ :state state
+ :init ctor
+ :main false
+ :methods [[ver [] String]
+ [in [String] Void]]))
+
+(defn -ctor
+ "The job of this constructor is to initialize state. The rest of the
+ initalization happens in the Applet init method."
+ []
+ [[] (agent {})])
+
+(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))))
+
+(defn -init
+ [this]
+ (let [thread (Thread. (partial my-repl this))]
+ (.start thread)
+ (send (.state this)
+ (fn [state]
+ (assoc state :repl-thread thread)))))
+
+(defn -ver
+ [this]
+ "0.5")
+
+(defn -in
+ [this string]
+ (when-let [input (:input (deref (.state this)))]
+ (.write input (.getBytes string))))