discuss-gnustep
[Top][All Lists]
Advanced

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

Re: Attempting to Create Obj-C Gecko Framework


From: Pascal Bourguignon
Subject: Re: Attempting to Create Obj-C Gecko Framework
Date: Tue, 10 Apr 2001 23:33:27 +0200

> On Monday, April 9, 2001, at 07:28 PM, Pascal Bourguignon wrote:
> > Writting  C functions could  do the  job, but  this would  probably be
> > quite labor intensive.
> >
> > A better way would be, IMHO, to take advantage of the dynamical aspect
> > of Objective-C.   Have a look at objc/objc.h  and objc/objc-api.h. The
> > Objective-C machinery  is published  as C functions  that you  can use
> > directly  from C++. You  could write  a single  C++ class  "ObjC" that
> > would allow  you to instanciate  Objective-C objects and to  send them
> > Objective-C messages. Minimally, something like this:
> >
>
> Pascal, thank you for the suggestion.  I will look into this and make
> some small demos.  The only question regarding that is how would the
> ObjC make a corresponding call to C++?  That is why I believed that a C
> wrapper may be the requirement.

Well, you're  right, in this  direction there's no  C API for  the C++
internals...  And it would  be needed  at least  to report  the action
messages to the targets.

I'll think of it some more later, but it could probably be done easily
enough with a  subclass of NSProxy on the Objective-C  side, a small C
stub, and the rest as a C++ class or mixin with methods similar to the
API fond in  objc/objc-api.h. Then subclasses of this  C++ class could
dispatch selectorsreceived from Objective-C to the correct C++ method,
either  with  a  "switch",   going  to  the  virtual  table  (compiler
dependent!), or with its own table  of C++ "IMP", that is, pointers to
C++ methods.

 +------------+
 |  NSProxy   |
 +------------+
       |
      /_\
       |
 +-------------+         +-------------+          +------------+
 |  CppProxy   |-------->|  C_to_Cpp   |--------->|   Cpp      |
 +-------------+         +-------------+          +------------+
 Receives a ObjC         Just a function          The method
 message (or             to send a C++            forwardInvocation()
 NSInvocation)           message:                 dispatches the message
 Prepare the args        cppObj->forward\         (SEL) by sending the
 and call C_to_Cpp.        Invocation(args);      actual C++ message.


When a C++ object needs to receive messages from Objective-C, it would
need to inherit  from Cpp, and implement the  methods corresponding to
the  messages  it expects  from  Objective-C  (or  it could  overwrite
directly  forwardInvocation and process  dynamically any  message from
Objective-C). A method  of Cpp would build and  return the CppProxy to
be  passed as  argument to  setDelegate:, setTarget:,  etc Objective-C
messages.


> > Note however  that the Objective-C  runtimes have some  differences in
> > GNUstep and MacOSX,  which means that two versions  of this ObjC class
> > (or two concrete subclasses) would have to be written
>
> No problem, I would tend to believe that once I've figured out how to do
> it, it shouldn't be TOO terribly different between the two (famous last
> words).  Isn't Apple contributing their gcc version of objc back to egcs?


--
__Pascal_Bourguignon__              (o_ Software patents are endangering
()  ASCII ribbon against html email //\ the computer industry all around
/\  and Microsoft attachments.      V_/ the world http://lpf.ai.mit.edu/
1962:DO20I=1.100  2001:my($f)=`fortune`;  http://petition.eurolinux.org/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]