All Manuals > LispWorks User Guide and Reference Manual > 42 Java classes and methods

NextPrevUpTopContentsIndex

com.lispworks.LispCalls.callIntV

com.lispworks.LispCalls.callIntA

com.lispworks.LispCalls.callDoubleV

com.lispworks.LispCalls.callDoubleA

com.lispworks.LispCalls.callObjectV

com.lispworks.LispCalls.callObjectA

com.lispworks.LispCalls.callVoidV

com.lispworks.LispCalls.callVoidA

Methods

public static int callIntV (String name, Object... args)

public static int callIntA (String name, Object[] args)

public static double callDoubleV (String name, Object... args)

public static double callDoubleA (String name, Object[] args)

public static Object callObjectV (String name, Object... args)

public static Object callObjectA (String name, Object[] args)

public static void callVoidV (String name, Object... args)

public static void callVoidA (String name, Object[] args)

Description

In the method name, the type specifies the return type, and V or A specifies whether the arguments are supplied as Variable arguments or Array. Otherwise the pairs of V and A methods behave the same.

The name argument is a string specifying a Lisp symbol. The name is parsed by a simple parser as described for com.lispworks.LispCalls.checkLispSymbol (with fboundp = true).

If the symbol is not found or is not fbound, these methods throw a RuntimeException with a string giving the reason for failure.

If the symbol is found, it is applied to the arguments args. For each argument, if it is a primitive type or of a class corresponding to a primitive type or a string, it is converted to the corresponding Lisp value. Otherwise it is passed as a jobject. See Types and conversion between Lisp and Java. The result of the call is converted to the return type of the method and returned from the method. The conversion of the result type allows any float to be returned as a double, but does not coerce between integers and floats. For the Object return value, the result must be either a Java object (jobject or an instance of standard-java-object), or a Lisp object that can be converted to a Java object. See Types and conversion between Lisp and Java.

The Lisp function is an ordinary Lisp function, but it needs to return the right value. Unless the call is using the Void callers (com.lispworks.LispCalls.callVoidA or com.lispworks.LispCalls.callVoidV), returning the wrong value will call the java-to-lisp-debugger-hook (see init-java-interface) with an appropriate condition, and then return zero of the correct type (that is 0, 0d0 or Java null) from the call.

The call to the Lisp function is wrapped such that trying to throw out of it does not actually finish the throw, and instead returns zero of the correct type from the call. It is also wrapped by a debugger hook, which is invoked if the code tries to enter the debugger (normally as a result of an unhandled error, but could be any call to cl:invoke-debugger). The hook calls the java-to-lisp-debugger-hook (see init-java-interface) with the condition, and then calls cl:abort. If there is no cl:abort restart inside the Lisp function that catches this abort, this causes returning a zero of the correct type.

An important issue to remember is that when delivering with shaking, LispWorks eliminates symbols for which there is no reference. If the only call to a Lisp symbol foo is from Java, LispWorks will not see the reference and it will eliminate foo. To guard against this, you can either pass foo in a list to the deliver keyword :keep-symbols, or more conveniently, use the function hcl:deliver-keep-symbols (see the LispWorks Delivery User Guide ), for example:

(defun function-called-from-java (arg1 arg2)
  ...
  )
 
(deliver-keep-symbols 'function-called-from-java)
Examples

int sum = com.lispworks.LispCalls.callIntV ("+", 2, 3, 10);
=> sum = 15

int position = com.lispworks.LispCalls.callIntV ("search", "r", "international");
=> position = 4

double logThree = com.lispworks.LispCalls.callDoubleV("log", 3);
=> logThree = 1.0986123


LispWorks User Guide and Reference Manual - 20 Sep 2017

NextPrevUpTopContentsIndex