Hi Ville,<div><br></div><div>You're aware it's 2010 by now? :-)</div><div><br></div><div>Bye,</div><div><br></div><div><br></div><div>Erik.<br><br><div class="gmail_quote">On Mon, Aug 30, 2010 at 7:57 PM, Ville Voutilainen <span dir="ltr"><<a href="mailto:vvoutilainen@common-lisp.net">vvoutilainen@common-lisp.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Author: vvoutilainen<br>
Date: Mon Aug 30 13:57:43 2010<br>
New Revision: 12908<br>
<br>
Log:<br>
Add an example for using a java class with CLASSPATH, invoking java<br>
functions from lisp code and finding the java class automagically<br>
as it's in CLASSPATH.<br>
<br>
<br>
Added:<br>
   trunk/abcl/examples/pure-lisp-to-java/<br>
   trunk/abcl/examples/pure-lisp-to-java/Main.java   (contents, props changed)<br>
   trunk/abcl/examples/pure-lisp-to-java/README<br>
   trunk/abcl/examples/pure-lisp-to-java/lispfunctions.lisp   (contents, props changed)<br>
<br>
Added: trunk/abcl/examples/pure-lisp-to-java/Main.java<br>
==============================================================================<br>
--- (empty file)<br>
+++ trunk/abcl/examples/pure-lisp-to-java/Main.java     Mon Aug 30 13:57:43 2010<br>
@@ -0,0 +1,39 @@<br>
+/*<br>
+ * Main.java<br>
+ *<br>
+ * Copyright (C) 2008 Ville Voutilainen<br>
+ * $Id$<br>
+ *<br>
+ * This program is free software; you can redistribute it and/or<br>
+ * modify it under the terms of the GNU General Public License<br>
+ * as published by the Free Software Foundation; either version 2<br>
+ * of the License, or (at your option) any later version.<br>
+ *<br>
+ * This program is distributed in the hope that it will be useful,<br>
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>
+ * GNU General Public License for more details.<br>
+ *<br>
+ * You should have received a copy of the GNU General Public License<br>
+ * along with this program; if not, write to the Free Software<br>
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.<br>
+ */<br>
+<br>
+import org.armedbear.lisp.*;<br>
+<br>
+public class Main<br>
+{<br>
+    /**<br>
+     * This example creates an Interpreter instance, loads our<br>
+     * lisp code from a file and then looks up a function defined<br>
+     * in the loaded lisp file and executes the function.<br>
+     *<br>
+     * The function takes a single parameter and invokes a java method<br>
+     * on the object provided. We provide our Main object as the parameter.<br>
+     *<br>
+     */<br>
+    public static int addTwoNumbers(int a, int b)<br>
+    {<br>
+       return a + b;<br>
+    }<br>
+}<br>
<br>
Added: trunk/abcl/examples/pure-lisp-to-java/README<br>
==============================================================================<br>
--- (empty file)<br>
+++ trunk/abcl/examples/pure-lisp-to-java/README        Mon Aug 30 13:57:43 2010<br>
@@ -0,0 +1,38 @@<br>
+ABCL Examples Building and Running Instructions<br>
+===============================================<br>
+<br>
+To compile<br>
+<br>
+    cmd$ javac  -cp ../../dist/abcl.jar  Main.java<br>
+<br>
+where the "../../../dist/abcl.jar" represents the path to your<br>
+abcl.jar file, which is built via the Ant based build.  This path<br>
+could be slightly different depending on how the system was<br>
+constructed, and possibly due to operating system conventions for<br>
+specifying relative paths.  However you resolve this locally, we'll<br>
+refer to this as '$ABCL_ROOT/dist/abcl.jar' for the rest of these<br>
+instructions.<br>
+<br>
+This compiles the Java source file "Main.java" into a JVM runtime or<br>
+class file named "Main.class".<br>
+<br>
+To run the example (Main.class for example) from a Unix-like OS use:<br>
+<br>
+    cmd$ export CLASSPATH=.<br>
+    cmd$ $ABCL_ROOT/abcl<br>
+<br>
+then, in abcl repl, use:<br>
+(load "lispfunctions")<br>
+(void-function)<br>
+<br>
+or in Windows use:<br>
+<br>
+    cmd$  set CLASSPATH=.<br>
+    cmd$  $ABCL_ROOT/abcl<br>
+<br>
+then, in abcl repl, use:<br>
+(load "lispfunctions")<br>
+(void-function)<br>
+<br>
+This will result in the Main class being found from the CLASSPATH, and you<br>
+can invoke the functions of the Main class from lisp code.<br>
<br>
Added: trunk/abcl/examples/pure-lisp-to-java/lispfunctions.lisp<br>
==============================================================================<br>
--- (empty file)<br>
+++ trunk/abcl/examples/pure-lisp-to-java/lispfunctions.lisp    Mon Aug 30 13:57:43 2010<br>
@@ -0,0 +1,34 @@<br>
+;;; lispfunctions.lisp<br>
+;;;<br>
+;;; Copyright (C) 2008 Ville Voutilainen<br>
+;;; $Id$<br>
+;;;<br>
+;;; This program is free software; you can redistribute it and/or<br>
+;;; modify it under the terms of the GNU General Public License<br>
+;;; as published by the Free Software Foundation; either version 2<br>
+;;; of the License, or (at your option) any later version.<br>
+;;;<br>
+;;; This program is distributed in the hope that it will be useful,<br>
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>
+;;; GNU General Public License for more details.<br>
+;;;<br>
+;;; You should have received a copy of the GNU General Public License<br>
+;;; along with this program; if not, write to the Free Software<br>
+;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.<br>
+<br>
+; we need to get the<br>
+; 1) class (Main)<br>
+; 2) classes of the parameters (int)<br>
+; 3) method reference (getting that requires the class<br>
+; of our object and the classes of the parameters<br>
+<br>
+; After that we can invoke the function with jcall,<br>
+; giving the method reference, the object and the parameters.<br>
+; The result is a lisp object (no need to do jobject-lisp-value),<br>
+; unless we invoke the method<br>
+; with jcall-raw.<br>
+(defun void-function ()<br>
+  (let* ((result (jstatic "addTwoNumbers" "Main" 2 4)))<br>
+    (format t "in void-function, result of calling addTwoNumbers(2, 4): ~a~%" result)))<br>
+<br>
<br>
_______________________________________________<br>
armedbear-cvs mailing list<br>
<a href="mailto:armedbear-cvs@common-lisp.net">armedbear-cvs@common-lisp.net</a><br>
<a href="http://common-lisp.net/cgi-bin/mailman/listinfo/armedbear-cvs" target="_blank">http://common-lisp.net/cgi-bin/mailman/listinfo/armedbear-cvs</a><br>
</blockquote></div><br></div>