Re: Objective-c Run-time headers
Re: Objective-c Run-time headers
- Subject: Re: Objective-c Run-time headers
- From: Alastair Houghton <email@hidden>
- Date: Fri, 6 Jul 2007 16:06:09 +0100
On 6 Jul 2007, at 15:16, Felipe Monteiro de Carvalho wrote:
thanks everyone,
On 7/6/07, Ronald Oussoren <email@hidden> wrote:
Why do you want to do that? It is much easier to use Objective-C,
you can easily mix pure-C and Objective-C in a project if you
already have a large set of the former. Building a Cocoa program
through the ObjC runtime API is possible, but a bit masochistic.
I want to building Object Pascal bindings for Cocoa.
Just a few ideas, which may or may not match what you had in mind:
If *I* were doing this, what I'd be inclined to do is to write an
"Objective" parser so that you can write ObjC-style method calls in
the middle of Pascal code. i.e. something like the following (excuse
my rusty Pascal :-); I'm sure I'll make all kinds of mistakes)
procedure SayHello (name : NSString)
var helloString : NSString;
begin
helloString = [@"Hello, " stringByAppendingString:name];
NSRunAlertPanel (@"Hello", helloString, nil, nil, nil, [])
end;
I'd be inclined to make Objective-C object types implicitly pointer
types, rather than always writing e.g. ^NSString as you would in ObjC
itself. I'd also be inclined to provide a sort of Pascal-ified
version of the usual ObjC syntax for interfaces etcetera, e.g.
@interface Foo : Bar
record
counter : Integer;
string : NSString
end;
- (id)someSelector:(Integer)myInt withString:(NSString)myStr;
@end
@implementation Foo
- (void)dealloc
begin
[string release];
string = nil
end;
- (id)someSelector:(Integer)myInt withString:(NSString)myStr
begin
if myInt < 4 then
counter := counter + 1
end;
[string release];
string = [myStr copy];
(* You need @return, I think, because writing
someSelector:withString: := string wouldn't work
well syntactically *)
@return string
end;
@end
Effectively you'd be defining Objective Pascal (or even "Objective
Object Pascal" :-D), which would provide ObjC classes with the same
(or similar) syntax to that actually used in ObjC. The benefit is
that all the Objective bits of the code would work in the same manner
as they do for ObjC, so you won't get lots of "how do I write this
method call" type questions. The only exception might be where C
varargs are being used, because you'll have to use a construct like
"array of const" for that.
Of course, this is somewhat harder than just making a binding,
because you'll want to make use of the various Mach-O segments that
are used by the Objective-C runtime so that you can e.g. make your
selector strings unique across the entire program. But I think the
results are much nicer, and one major benefit is that the
documentation works better since the message passing syntax is the
same (or similar), and you won't have to resort to unpleasant
mangling of selector names in the code.
One other thing that deserves considerable thought is what to do
about Cocoa exceptions (NSException et al) and how they fit in with
Object Pascal exceptions. You'll need to ponder that even if you
just go for a more straightforward binding instead of a language
extension of the kind I'm advocating here.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden