[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

creating scheme class instance inside a C++ extension


>From inside a C++ extension, how do I make an instance of a scheme class?
Since classes in PLT 200 are implemented in mzlib, it's not clear to me
how to do this.

Here's my application:

Scheme registers callbacks with my extension.
When an event occurs I'd like one of the callback parameters
to be an instance of a scheme class which describes the event.
For example, when the mouse enters a rectangle:

  (define rect (make-object padrect%))

  (send rect bind "<Enter>" callback)

where callback was defined as

  (define (callback event) ...)

and event is an instance of padevent%.

One solution might be to pass an event instance when registering
the callback.  When an event occurred the extension would fill in
the instance and return it.  For example

  (define event (make-object padevent%))
  (send rect bind "<Enter>" callback event)

Would that work?  Call by reference?

Also, how do I access a class's fields from within an extension?
The class is really a struct and the C API includes functions ref
and set.  So, I'd need to figure out the relationship between field
names and fields indexes?