[KLUG Programming] Objective-C Anyone?
Adam Williams
programming@kalamazoolinux.org
12 Aug 2003 08:02:53 -0400
--=-P+zhhr3RP3yFdzM5Zm1O
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
> Anyone on this list know Objective C? oGo is written in Objective-C and
> I've managed to locate the DocumentAPI (as they call it). But, Wow!,
> does this not look like C.
Ok, it is starting to make a little sense. Also it appears that
Objective-C is Apple's native tongue, so maybe I'll get lucky finding an
Objective-C guy here afterall.
Anyway here is the issue -
1. I was going to wrap objects around the oGo XML-RPC/ZideStore
services. In talking with some people it became clear that this was
pretty stupid. Since your going to be running this service on the oGo
server just link to the libraries provided in the opengroupware-docapi
package. Which *SHOCKINGLY* provides objects like oGoAccount,
oGoContact, etc.... (Dherr!)
2. oGo is written in Objective-C
3. There are no CORBA (ORBit) bindings for Objective-C
4. There are ORBit bindings for C, C++, and Python that seem very
mature. Less mature ones for Perl, TCL, etc...
<aside> 5. It was pointed out to me that PHP's recent CORBA support
(--with-universe) would make using these objects totally native - which
just has me more rev'd up. </aside>
So I need to "wrap" the oGo DocAPI libraries in C or C++. I've found
some UseNet posts on something like this. (attached) If someone wants
to take a gander at them.
There is also a Python utility for swallowing ObjC libraries into
packages. But I don't know enough python to write a HelloWorld app; so
I'm not pursuing that angle.
--=-P+zhhr3RP3yFdzM5Zm1O
Content-Disposition: attachment; filename=Wrapper1.text
Content-Type: text/plain; name=Wrapper1.text; charset=UTF-8
Content-Transfer-Encoding: 7bit
Lonnie Ezell <kilishan@home.com> wrote:
> Forgive me if this is the wrong newsgroup. I've done quite a bit of
> searching and cannot find on information on creating C++ wrappers for
> objective-C classes.
> Can anyone point me in the right direction?
well there would be two ways to go about it. if you can mix Objective C and
C++ (ObjC++ i guess), then you can just do:
@interface Foo : Object
- a;
- b;
- (int)cWithArg: (double)x;
@end
class foo {
foo *objc_obj;
public :
Foo() { objc_obj = [Foo new]; }
~Foo() { [objc_obj free]; }
foo &a() { return [objc_obj a]; }
foo &b() { return [objc_obj b]; }
int c(double x) { return [objc_obj cWithArg: x]; }
};
if you can't, or you don't know if you can, then you would have to use an
intermediate C wrapper:
/* --- in a header file --- */
#ifdef __cplusplus
extern "C" {
#endif
void *Foo_new(void);
void *Foo_free(void *);
void *Foo_a(void *);
void *Foo_b(void *);
int Foo_c(void *, double);
#ifdef __cplusplus
}
class foo {
void *objc_obj;
public :
Foo() { objc_obj = Foo_new(); }
~Foo() { Foo_free(objc_obj); }
void *a() { return Foo_a(objc_obj); }
/* ... */
}
#endif
#ifdef __OBJC__
@interface Foo : Object
/* ... */
@end
#endif
/* --- in an .m file --- */
void *
Foo_new(void)
{
return [Foo new];
}
void *
Foo_free(void *obj_)
{
Foo * const obj = obj_;
return [foo free];
}
void *
Foo_a(void *obj_)
{
Foo * const obj = obj_;
return [obj a];
}
/* ... etc. ... */
if you really want to be cool, you could whip up a pre-processor for this
without too much trouble (i.e. write your class as an IDL and then have it
generate the ObjC, C++ and (if needed) C interfaces and skeletons
automatically).
--=-P+zhhr3RP3yFdzM5Zm1O
Content-Disposition: attachment; filename=Wrapper2.text
Content-Type: text/plain; name=Wrapper2.text; charset=UTF-8
Content-Transfer-Encoding: 7bit
Why not just use the dynamics of ObjC? This is usiing GNUstep Foundation
classes, which I am happily learing. This is just a simple example, would
need a little work.
Mike
- objc.m ---
id createObject( char *aClass ) {
NSString *aclass = [NSString stringWithCString: aClass];
return [NSClassFromString( aclass ) alloc];
}
void sendMessage( Obj aObj, char *aSel ) {
NSString *nssel = [NSString stringWithCString: aSel];
SEL sel = NSSelectorFromString( nssel );
[aObj performSelector: sel];
}
void InitNSEnviron( int argc, char **argv ) {
[NSProcessInfo initializeWithArguments: argv count: argc environment:
environ];
}
- main.cpp ---
extern "C" {
void initNSEnviron( int argc, char **argv );
void *createObject( char *aClass );
void sendMessage( void *aObject, char *aMessage );
}
int main( int argc, char **argv ) {
initNSEnviron( argc, argv );
puts("in c++!");
void *obj = createObject( "Button" );
sendMessage( obj, "mouseMove" );
puts("in c++2!");
}
"Lonnie Ezell" <kilishan@home.com> wrote in message
news:kilishan-2803012225290001@c1080443-b.sprgfld1.mo.home.com...
> Forgive me if this is the wrong newsgroup. I've done quite a bit of
> searching and cannot find on information on creating C++ wrappers for
> objective-C classes.
>
> Can anyone point me in the right direction?
>
> Thanks, and forgive the intrusion.
> Lonnie
>
--=-P+zhhr3RP3yFdzM5Zm1O--