Hi Henrik,

> Hi Alex, I just took a look at the old java gui download.
> ...
> communicating with a running JVM from PL.

The starting point is the class "java/Reflector.java", together with the
start-up shell script "java/vm".

'Reflector' is a kind of "Java functionality server". It mediates - as
you observed - between the Java and PicoLisp worlds.

Also included is a demo Java library "java/Util.java", containing some
Java functions be callable from PicoLisp. You can start it as

   $ java/vm java/util.jar &

Now the Java functionality server is running in the background. The
startup script created a named pipe "fifo/java" where the server is
listening at.

Now any PicoLisp program can load "lib/java.l", and requests the
execution of Java functions on that server:

   : (load "lib/java.l")
   -> java

   : (java 'Util 'md5 "This is a string")
   -> 87704939138141002822102625569266896500
   : (hex @)                             
   -> "41FB5B5AE4D57C5EE528ADB00E5E8E74"

   : *Pid
   -> 15561

If you look now into the "fifo/" directory

   prw-r--r-- 1 abu abu 0 May 27 09:15 java|
   prw-r--r-- 1 abu abu 0 May 27 09:15 java15561|

you see that the PicoLisp process created another fifo with its PID in
the name, to receive the answers from the server.

The types of requests the Reflector understands is rather limited. It
could be

   - static methods (when the second argument is a symbol or string
     (like 'md5' above), or

   - methods invoked on a 'new' object which is created on the fly (when
     the second argument is NIL or a list)

In the second case, NIL causes the creation of a Java object of the
given class (in the first argument). I don't remember exactly what a
list of classes means (calling getConstructor() with a list of classes),
as I never needed that. If you should need it, we must investigate a
little more ...

> fork routine) and then having the Java end use the code in inOut.java
> to print to and read from this port?

As you see from the above examples, the PicoLisp side doesn't need to
worry about the communication details (just call 'java'), and the Java
side also doesn't need that, as the Java reflection api takes care of
that so that you can concentrate on the Java side just on writing proper

> Btw there are two java folders, java and java2, what is the difference?

'java' should be sufficient here. 'java2' contains only the newer
version of the GUI (Swing instead of AWT), and the Z3dField class for
the 3D graphics (used in the flight simulator).

- Alex
UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe

Reply via email to