[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: creating scheme class instance inside a C++ extension
At Fri, 12 Apr 2002 12:37:46 -0700 (PDT), Ron Stanonik wrote:
> From inside a C++ extension, how do I make an instance of a scheme class?
The answer depends on whether you mean a class that has been extended
from Scheme, or a "primtive" class like `tree%' in the MzScheme
example.
In the former case, it's essentially the same as in Scheme. The
extension will need to get `make-object' from the "class.ss" library,
get the class value, and them combined them (with initialization
arguments) using _scheme_apply().
In the latter case, you can instantiate the underlying C++ class and
then do something like MarshallTree() in the tree.cxx example.
> 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?
I'd advise against mutating event records this way, because there are
so many situations where you want re-entrant event handlers.
> 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?
Here again, I recommend doing essentially the same thing as in Scheme:
get a field accessor via `class-field-accessor' and use it on an object
with _scheme_apply().
Matthew