www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.dwt - Help with dwt-cocoa types

reply Jacob Carlborg <doobnet gmail.com> writes:
I'm porting swt-cocoa to D and I've run into some type problems that I'm 
not sure how to best solve.

There are many types that Java don't support like pointers for example 
and so they replace them with int. I'm now trying to replace them back 
to, as closely match to, the original types. I'm thinking like this: 
when the int represents a struct, enum, typedef or other C type I just 
keep that C type in D. But when the int represents an objective-c (objc) 
class there are some problems. All objc classes inherit (or based on) 
from a C type called "id" that looks like this:

typedef id (*IMP)(id, SEL, ...);

http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html

If the int represents an objc class that is a value type I replace that 
with the type "id" in D.

If the int represents pointer to an objc class I replace that with a 
class in D (because it's a class in Java)

If the int represents a pointer to pointer to a objc class I replace 
that with the type "id**" in D.

But at some places 

when they use type type "id" in objc they use in Java a class called 
"id" (which contains an int), but at other places they use an int for 
that in Java. That I don't understand.

So what do you think about all this?
Jul 08 2008
parent reply Frank Benoit <keinfarbton googlemail.com> writes:
Jacob Carlborg schrieb:
 typedef id (*IMP)(id, SEL, ...);
I think this typedef shows the declaration of 'IMP', not of 'id'. struct objc_class{ // ... } struct objc_selector{ // ... } struct objc_object { Class isa; // ... } alias objc_class * Class; alias objc_object * id; alias objc_selector * SEL; alias extern(C) id function(id, SEL, ...) IMP;
Jul 08 2008
parent Jacob Carlborg <doobnet gmail.com> writes:
Frank Benoit wrote:
 Jacob Carlborg schrieb:
 typedef id (*IMP)(id, SEL, ...);
I think this typedef shows the declaration of 'IMP', not of 'id'. struct objc_class{ // ... } struct objc_selector{ // ... } struct objc_object { Class isa; // ... } alias objc_class * Class; alias objc_object * id; alias objc_selector * SEL; alias extern(C) id function(id, SEL, ...) IMP;
That makes sense. And here we can see how bad C styled function pointers are.
Jul 09 2008