문제

I'm very new to lisp and pretty new to java as well. I was working on a trivial game in java and I thought that it would be interesting to interact with the game as I was coding it through the REPL. I have been following Practical Common Lisp and I have knowledge of basic function structure. I started using armed bear common lisp--an implementation that runs on the java virtual machine--and was able to code some basic functions for creating guis, such as:

(defconstant +jframe+ "javax.swing.JFrame")

(defun make-frame (length width &key visible)
  "Create a +jframe+"
  (let ((frame (jnew (jconstructor +jframe+))))
    (jcall (jmethod +jframe+ "setSize" "int" "int")
       frame length width)
    (if visible (frame-is-visible t frame))
    frame))

However I can not figure out how to access user defined classes from lisp. The implementation as a whole seems pretty poorly documented, and I'm finding difficulty getting started using java specific things from within lisp. For example, I have a compiled character class called "Character". But when I call (jclass "Character") I get a "class not found" error. Is it possible to make abcl aware of my classes from within lisp?

도움이 되었습니까?

해결책

If you want to create an instance of a Java class that you've written yourself and that is packaged in a jar file, use add-to-classpath:

(add-to-classpath '("Character.jar"))

Then, (jnew "org.example.Character") should give you an instance of your Character class (assuming it's in the org.example namespace).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top