Commits

Ning Sun committed 3693e55

add macro for defhandler

  • Participants
  • Parent commits 6c75a9b

Comments (0)

Files changed (2)

 (defproject link "0.1.0-SNASHOT"
-  :description "A straightforward clojure wrapper for java nio framework"
+  :description "A straightforward (not-so-clojure) clojure wrapper for java nio framework"
   :dependencies [[org.clojure/clojure "1.3.0"]
-                 [io.netty/netty "3.3.1.Final"]])
+                 [io.netty/netty "3.3.1.Final"]
+                 [gloss "0.2.1-alpha2-SNAPSHOT"]])
 

File src/link/core.clj

 (ns link.core)
+
+(defmacro ^{:private true} make-handler-macro [evt]
+  (let [handler-name (str "on-" evt)
+        symbol-name (symbol handler-name)
+        args-vec-sym (symbol "args-vec")
+        body-sym (symbol "body")]
+    `(defmacro ~symbol-name [~args-vec-sym & ~body-sym]
+       `{(keyword ~~handler-name) (fn ~~args-vec-sym ~@~body-sym)})))
+
+(make-handler-macro open)
+(make-handler-macro close)
+(make-handler-macro message)
+(make-handler-macro error)
+(make-handler-macro connect)
+(make-handler-macro disconnect)
+
+(defmacro defhandler [n & body]
+  `(def ~n (merge ~@body)))
+
+