有没有更聪明的方法来使用位于另一个名称空间中的代码
Is there a smarter way of using the code located in another namespace
我的核心页面上有这个。它创建 window 但不绘制任何东西
(deftype Program []
GLEventListener
(display [this drawable] (in-ns 'game-c.drawtriangle))
(init [this drawable] "init")
(dispose [this drawable] "dispose")
(reshape [this drawable x y width height] "reshape")
)
;set up and start window methods/functions
(def glp (GLProfile/getDefault))
(def caps (GLCapabilities. glp))
(def window (GLWindow/create caps))
(def ani (FPSAnimator. window 60 true))
(doto window
(.addGLEventListener (Program.))
(.setSize 600 600)
(.setTitle "CloGame")
(.setVisible true)
(.start ani)
)
这是在window上绘制三角形的部分。但它不会那样做。我刚启动 repl,它显示空白 window、一个函数 return 值和一条错误消息(详见下文)
(ns game-c.drawtriangle)
(def gl (.getGL4 (.getGL window)))
(def tri [ [0.0 0.0] [0.5 0.0] [0.5 0.5] ])
(doto gl
(.glCreateVertexArrays 1 tri)
)
这是 repl 输出
#object[clojure.lang.Namespace 0x49db0a8e "game-c.core"]
CompilerException java.lang.RuntimeException:
com.jogamp.opengl.GLException: Caught IllegalStateException: Can't
change/establish root binding of: *ns* with set on thread nREPL-worker-
1-Display-.x11_:0-1-EDT-1, compiling:(game-c/core.clj:33:2)
我认为可能有另一种使用位于 drawtriangle 中的代码的方法,但我不确定你会怎么做
试试这个:
(ns game-c.core
(:require [game-c.drawtriangle :as tri] ))
...
(display [this drawable] (tri/drawtriangle))
...
和
(ns game-c.drawtriangle
(:require [game-c.core :as core] ))
(def gl (.getGL4 (.getGL core/window)))
...
我的核心页面上有这个。它创建 window 但不绘制任何东西
(deftype Program []
GLEventListener
(display [this drawable] (in-ns 'game-c.drawtriangle))
(init [this drawable] "init")
(dispose [this drawable] "dispose")
(reshape [this drawable x y width height] "reshape")
)
;set up and start window methods/functions
(def glp (GLProfile/getDefault))
(def caps (GLCapabilities. glp))
(def window (GLWindow/create caps))
(def ani (FPSAnimator. window 60 true))
(doto window
(.addGLEventListener (Program.))
(.setSize 600 600)
(.setTitle "CloGame")
(.setVisible true)
(.start ani)
)
这是在window上绘制三角形的部分。但它不会那样做。我刚启动 repl,它显示空白 window、一个函数 return 值和一条错误消息(详见下文)
(ns game-c.drawtriangle)
(def gl (.getGL4 (.getGL window)))
(def tri [ [0.0 0.0] [0.5 0.0] [0.5 0.5] ])
(doto gl
(.glCreateVertexArrays 1 tri)
)
这是 repl 输出
#object[clojure.lang.Namespace 0x49db0a8e "game-c.core"]
CompilerException java.lang.RuntimeException:
com.jogamp.opengl.GLException: Caught IllegalStateException: Can't
change/establish root binding of: *ns* with set on thread nREPL-worker-
1-Display-.x11_:0-1-EDT-1, compiling:(game-c/core.clj:33:2)
我认为可能有另一种使用位于 drawtriangle 中的代码的方法,但我不确定你会怎么做
试试这个:
(ns game-c.core
(:require [game-c.drawtriangle :as tri] ))
...
(display [this drawable] (tri/drawtriangle))
...
和
(ns game-c.drawtriangle
(:require [game-c.core :as core] ))
(def gl (.getGL4 (.getGL core/window)))
...