Re: Accessing objects from plain c code
Re: Accessing objects from plain c code
- Subject: Re: Accessing objects from plain c code
- From: Nicko van Someren <email@hidden>
- Date: Thu, 15 Jan 2004 21:26:02 +0000
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
_______________________________________________
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.