This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
executing scheme from Java
- To: kawa at sourceware dot cygnus dot com
- Subject: executing scheme from Java
- From: "Walter C. Pelissero" <walter at pelissero dot org>
- Date: Thu, 17 May 2001 18:00:10 +0100
- Reply-To: walter at pelissero dot org
I tried, following the instructions in kawa.texi, to compile a Scheme
file in a class file and then run one of the methods (functions) from
Java. Everything seems to work properly unless character arguments
are involved in cross module calls.
Here is an example:
foo.scm:
(require <bar>)
(define (execute args) <void>
(display (bar #\x))
(newline))
bar.scm:
(define (bar c)
(string c))
run.java:
import gnu.kawa.util.*;
import kawa.standard.*;
import gnu.mapping.*;
import gnu.expr.*;
import java.lang.reflect.*;
public class run
{
public static Interpreter getInterpreter()
{
if (Interpreter.defaultInterpreter == null)
{
Interpreter.defaultInterpreter = Interpreter.getInstance(null);
Environment.setCurrent(Interpreter.defaultInterpreter.getEnvironment());
}
return Interpreter.defaultInterpreter;
}
public static void main (String args[])
{
try {
getInterpreter();
int length = args.length, i;
LList list = new LList();
for (i = 2; i < length; ++i) {
FString scstr = new FString(args[i]);
list = new Pair(scstr, list);
}
LList result = (new run()).execute(args[0], args[1], list);
} catch (Exception e) {
e.printStackTrace();
}
}
public LList execute (String class_name, String method, Object args)
throws Exception
{
Class c = Class.forName(class_name);
Method m = c.getMethod(method, new Class[] {
(new Object()).getClass()
});
return (LList) m.invoke(c.newInstance(), new Object[] { args });
}
}
The error:
java.lang.reflect.InvocationTargetException: java.lang.NullPointerException
at bar.bar(bar.scm, Compiled Code)
at foo.execute(foo.scm, Compiled Code)
at java.lang.reflect.Method.invoke(Native Method)
at run.execute(run.java, Compiled Code)
at run.main(run.java, Compiled Code)
--
walter pelissero
http://www.pelissero.org