Changes between Version 7 and Version 8 of JavaScriptingAPI

03/16/09 21:35:16 (13 years ago)



  • JavaScriptingAPI

    v7 v8  
    4141!AbclScriptEngine implements the {{{javax.script.Invocable}}} interface. This interface allows to directly call functions and methods in the script, as well as to get implementations of Java interfaces from the script. This is only partially possible with Lisp since it has functions, but not methods - not in the traditional OO sense, at least, since Lisp methods are not attached to objects but belong to generic functions. Thus, the invokeMethod() is not implemented and throws an !UnsupportedOperationException when called. The invokeFunction() method should be used to call both regular and generic functions.
    43 TBD
     43=== Implementation of Java interfaces ===
     45ABCL can use the Java reflection-based proxy feature to implement Java interfaces in Lisp. It has several built-in ways to implement an interface, and supports definition of new ones. The jmake-proxy generic function is used to make such proxies. It has the following signature:
     47{{{jmake-proxy interface implementation &optional lisp-this ==> proxy}}}
     49interface is a Java interface metaobject or a string naming a Java interface.
     50implementation is the object used to implement the interface - several built-in methods of jmake-proxy exist for various types of implementations.
     51lisp-this is an object passed to the closures implementing the Lisp "methods" of the interface.
     53The returned proxy is an instance of the interface, with methods implemented with Lisp functions.
     55Built-in interface-implementation types include:
     57 * a single Lisp function which upon invocation of any method in the interface will be passed the method name, the Lisp-this object, and all the parameters. Useful for interfaces with a single method, or to implement custom interface-implementation strategies.
     58 * an hash-map of method-name -> Lisp function mappings. Function signature is (lisp-this &rest args).
     59 * a Lisp package. The name of the Java method to invoke is first transformed in an idiomatic Lisp name (javaMethodName becomes JAVA-METHOD-NAME) and a symbol with that name is searched in the package. If it exists and is fbound, the corresponding function will be called. Function signature is as the hash-table case.
     61This functionality is exposed by the !AbclScriptEngine with the two methods getInterface(Class) and getInterface(Object, Class). The former returns an interface implemented with the current Lisp package, the latter allows the programmer to pass an interface-implementation object which will in turn be passed to the jmake-proxy generic function.