0

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?

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
  • A recent ABCL manual: https://code.google.com/p/abcl-dynamic-install/downloads/detail?name=abcl-manual-20120205a.pdf It might be best to ask ABCL specific questions and suggest improvements on the ABCL mailing list. See http://common-lisp.net/project/armedbear/ – Rainer Joswig Jul 12 '12 at 07:03
  • Please clarify: which classes do you have in mind - Java classes from jars or Lisp CLOS classes defined with `defclass`? – dmitry_vk Jul 13 '12 at 04:52
  • All classes in Java have package prefixes. So you should provide something like `(jclass "my.package.Character")` – Vsevolod Dyomkin Jul 16 '12 at 12:34

1 Answers1

2

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).

Rudi
  • 106
  • 1
  • 2