getMethod() works and works not

A

Alexander Burger

Patricia Shanahan said:
What is the getMethod translation? Does the class in question have an
"add" method member, either by declaration or inheritance, with the

Oops, you are right. I forgot to fix that line when preparing a reduced
example. 'JTextArea' should have been the variable 'area'. Anyway, it
works now :)

Thanks.
 
A

Alexander Burger

Mike Schilling said:
3. Reject the ones with the wrong number of arguments. (Be careful here if
you're going to support variable-argument methods)

I won't. This would introduce too much runtime overhead. Instead I'll go with
passing arrays. The following works:

(java "java.lang.String" "format" "%4$2s %3$2s %2$2s %1$2s" '("a" "b" "c" "d"))
 
A

Alessio Stalla

Mike Schilling said:
To begin with, why is the OP using reflection at all?  It's of no value in
the code actually posted, which could simply call method the normal way..

Sure, but this is just a prepared, reproducible example.

The actual code is the Java version of PicoLisp. The plain runtime
system ist at "http://software-lab.de/ersatz.tgz", the full system
including sources at "http://software-lab.de/picoLisp.tgz".

There is a generic 'java' function which allows to call arbitrary
constructors and methods, on arbitrary objects. And, this indeed works
most of the cases, but sometimes (like here for 'JPanel' and 'add') not.

The lisp-level function 'java' accepts four syntax patterns:

   (java 'obj ['cnt]) -> any
      Converts a Java object back to Lisp data

   (java 'obj 'msg 'any ..) -> obj
      Invokes a method 'msg' on an object 'obj' with arguments 'any'

   (java 'cls 'msg 'any ..) -> obj
      Invokes a static method 'msg' in class 'cls' with arguments 'any'

   (java 'cls 'T 'any ..) -> obj
      Returns a new object of class 'cls' by calling the constructor of
      that class with arguments 'any'.

For example, this works (analog to the posted plain Java example):

   (setq
      frame (java "javax.swing.JFrame" T "Title")
      panel (java frame "getContentPane")
      area (java "javax.swing.JTextArea" T 10 40) )

   (java frame "setSize" 300 200)
   (java frame "setLocation" 100 100)

   # ??? (java panel "add" JTextArea)

   (java frame "setVisible" T)

Just the line with "???" does not, and this is the case which also has
"???" in the original post.

You can have a look at how ABCL does it. Your java operator is called
jcall in ABCL, and it does perform some dynamic dispatch in the vein
of what javac does for method resolution; though it probably isn't
100% compatible with what the JLS specifies, it's "good enough" for
the cases we encountered so far. Some pointers:

(incomplete) documentation of ABCL's Java FFI:
http://trac.common-lisp.net/armedbear/wiki/JavaFfi

Implementation of jcall and other primitives:
http://trac.common-lisp.net/armedbear/browser/trunk/abcl/src/org/armedbear/lisp/Java.java

ABCL home page: http://common-lisp.net/project/armedbear

Cheers,
Alessio
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top