This is the mail archive of the kawa@sourceware.org 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]
Other format: [Raw text]

Re: use macros to generate java calls


On 12/05/2011 07:09 AM, Jamison Hope wrote:
Of course, there are times when the built-in facility isn't applicable,
like
if you can't invoke a constructor (e.g. have to retrieve a singleton or
call
a factory method) or if the methods you want to invoke on the object aren't
add/set or take more (or less) than one argument.

Another Kawa feature I haven't plugged enough: Custom object builders. This is a work in progress, which I started on for providing JavaFX bindings - see http://per.bothner.com/blog/2011/JavaFX-using-Kawa-intro/ I encourage experimentation with this feature.

The basic idea is you can define a class which extends
gnu.kawa.reflect.CompileBuildObject.  The default implementation
provides the functionality described in
  http://www.gnu.org/software/kawa/Allocating-objects.html
However,  CompileBuildObject has various extension points allowing you to
override the behavior for a specific class.

For example gnu/kawa/javafx/GroupObjectBuilder.scm handles some of the
JavaFX classes.

You then associate this custom CompileBuildObject with the class it's
supposed to handle by definining the class name as the value of a
constant with a special magic name, for example:

;; from gnu/kawa/javafx/defs.scm
(define-constant {gnu.kawa.reflect/ObjectBuilder}:javafx.scene.shape.Path
  "gnu.kawa.javafx.GroupObjectBuilder")

The magic name '{gnu.kawa.reflect/ObjectBuilder}:javafx.scene.shape.Path
yields a compound symbol with local name "javafx.scene.shape.Path"
and namespace URI "gnu.kawa.reflect/ObjectBuilder".  When compiling a
constructor for javafx.scene.shape.Path, the compiler will look if
there is a constant binding for this special name.

(Using define-constant this way allows binding custom constructors
that follow lexical scoping (including require/import) without
cluttering up the run-time with harder-to-manage procedure properties
or global bindings.)
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


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