[armedbear-devel] java/abcl hello-world example

David Dreisigmeyer david.dreisigmeyer at gmail.com
Sat Aug 21 23:15:14 UTC 2010


Hi Robert,

I did see that (thanks for the link).  This example is included with
the source code for abcl also (in examples/lisp-to-java).  I guess
what I'd need help with is how to to make a jar file from the
Main.java from examples/lisp-to-java (see below) file and then use
that from abcl.

Thanks again, I really appreciate it,

-Dave

import org.armedbear.lisp.*;

public class Main
{
    /**
     * This example creates an Interpreter instance, loads our
     * lisp code from a file and then looks up a function defined
     * in the loaded lisp file and executes the function.
     *
     * The function takes a single parameter and invokes a java method
     * on the object provided. We provide our Main object as the parameter.
     *
     */
    public static void main(String[] argv)
    {
	try
	    {
		Main thisObject = new Main();
		Interpreter interpreter = Interpreter.createInstance();
		interpreter.eval("(load \"lispfunctions.lisp\")");
		// the function is not in a separate package, thus the
		// correct package is CL-USER. Symbol names are
		// upper case. Package needs the prefix, because java
		// also has a class named Package.
		org.armedbear.lisp.Package defaultPackage =
		    Packages.findPackage("CL-USER");
		Symbol voidsym =
		    defaultPackage.findAccessibleSymbol("VOID-FUNCTION");
		Function voidFunction = (Function) voidsym.getSymbolFunction();
		voidFunction.execute(new JavaObject(thisObject));
	    }
	catch (Throwable t)
	    {
		System.out.println("exception!");
		t.printStackTrace();
	    }
    }
    public int addTwoNumbers(int a, int b)
    {
	return a + b;
    }
}


On Sat, Aug 21, 2010 at 6:36 PM, Robert Dodier <robert_dodier at yahoo.com> wrote:
> David, have you seen this page?
>
> http://common-lisp.net/project/armedbear/doc/abcl-user.html
>
> It has some simple examples of calling from Java to ABCL and vv.
>
> Hope this helps,
>
> Robert Dodier
>
>
>
>
>




More information about the armedbear-devel mailing list