This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

executing scheme from Java


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]