Skip to content

Commit

Permalink
Move all initialization to neko.init/init
Browse files Browse the repository at this point in the history
Also pass device port from lein-droid.
  • Loading branch information
alexander-yakushev committed Sep 4, 2013
1 parent 7917d42 commit e34eeb5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/clojure/neko/init.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
(ns neko.init
"Contains functions for neko initialization and setting runtime options."
(:require [neko.init.options :as options]
neko.compilation))
[neko context log resource compilation threading]))

(defmacro
^{:private true
Expand Down Expand Up @@ -43,7 +43,9 @@
[port other-args]
(when (or (not options/*release-build*)
options/*start-nrepl-server*)
`(apply start-repl :port ~port ~other-args)))
`(let [port# (or ~port ~options/*nrepl-port* 9999)]
(apply start-repl :port port# ~other-args)
(neko.log/i "neko.init" (str "Nrepl started at port " port#)))))

(defn enable-compliment-sources
"Initializes compliment sources if theirs namespaces are present."
Expand All @@ -53,6 +55,10 @@
((resolve 'neko.compliment.ui-widgets-and-attributes/init-source))
(catch Exception ex nil)))

(def ^{:doc "Represents if initialization was already performed."
:private true}
initialized? (atom false))

(defn init
"Initializes neko library.
Expand All @@ -61,9 +67,14 @@
key-value fashion. The value of `:classes-dir` specifies the path
where neko should store compiled files. Other optional arguments are
directly feeded to the nREPL's `start-server` function. "
[context & {:keys [classes-dir port] :or {classes-dir "classes", port 9999}
[context & {:keys [classes-dir port] :or {classes-dir "classes"}
:as args}]
(enable-dynamic-compilation context classes-dir)
;; Ensure that `:port` is provided, pass all other arguments as-is.
(start-nrepl-server port (mapcat identity (dissoc args :classes-dir :port)))
(enable-compliment-sources))
(when-not @initialized?
(alter-var-root #'neko.context/context (constantly context))
(alter-var-root #'neko.resource/package-name (constantly (.getPackageName context)))
(enable-dynamic-compilation context classes-dir)
;; Ensure that `:port` is provided, pass all other arguments as-is.
(start-nrepl-server port (mapcat identity (dissoc args :classes-dir :port)))
(neko.threading/init-threading)
(enable-compliment-sources)
(reset! initialized? true)))
5 changes: 5 additions & 0 deletions src/clojure/neko/init/options.clj
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@
^{:dynamic true
:doc "Application's root package name."}
*package-name*)

(def
^{:dynamic true
:doc "Port to start nRepl server on."}
*nrepl-port*)

0 comments on commit e34eeb5

Please sign in to comment.