Re: Accessing objects from plain c code
Re: Accessing objects from plain c code
- Subject: Re: Accessing objects from plain c code
- From: Robert Tillyard <email@hidden>
- Date: Fri, 16 Jan 2004 00:41:14 +0000
On 15 Jan 2004, at 9:26 pm, Nicko van Someren wrote:
On 15 Jan 2004, at 20:35, Sarah Dumoulin wrote:
I have a linux c program which I am trying to add a cocoa interface
to.
I've made a front end with xcode, but I need to be able to call some
of my
objective-c methods from my c code (to update an opengl context).
I'm sure
that there's some very simple and obvious way of doing this, but I'm
don't
know what it is. Do I just include the header files for the
objective c
classes and call the functions as if they were plain C functions? Is
there
a generic header file that I include to deal with the "id" type?
E.g. I have a class Viewer with a method update. Update has an
integer
argument. I want my c code to call the update method. How would I
do this?
The critical thing to know is that if you have a file full of standard
C code but you give the source file a .m extension instead of a .c
extension Xcode will compile it with the Objective C compiler and in
general it will still work. Also,
plain C functions compiled from a .m file can invoke Objective C
messages. Finally note is that object references are just C pointers
with special meaning to the Objective C compiler.
So, you can have some code in, say, awakeFromNib: that puts a copy of
an object reference to some controller in a place that can be seen
from your C code that compiled from a .m file and you can call the C
functions in that file to issue messages to the Objective C side.
Cheers,
Nicko
Do you have an example of the syntax used to call a method in
Objective-C from C please. I have a thread that is ftp-ing things from
a remote server and I would like to send the progress to the GUI so
that I can display a progress bar.
Thanks, Regards, Rob.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.