Re: Calling a Cocoa library from C

2011-11-14 Thread Nathan Sims
The help so far has been very edifying. Now, I go to create a 'Cocoa Library' project in Xcode 3.2.6, and it generates a libaaa.h and a libaaa.m for me. But in the .m file, there's an '@implementation libaaa' line. I'm confused, I thought a Cocoa library was a number of *.o (compiled .m files)

Re: Calling a Cocoa library from C

2011-11-14 Thread Jens Alfke
On Nov 14, 2011, at 9:47 AM, Nathan Sims wrote: Now, I go to create a 'Cocoa Library' project in Xcode 3.2.6, and it generates a libaaa.h and a libaaa.m for me. But in the .m file, there's an '@implementation libaaa' line. I'm confused, I thought a Cocoa library was a number of *.o

Re: Calling a Cocoa library from C

2011-11-14 Thread Kyle Sluder
On Nov 14, 2011, at 9:47 AM, Nathan Sims newsli...@autonomy.caltech.edu wrote: The help so far has been very edifying. Now, I go to create a 'Cocoa Library' project in Xcode 3.2.6, and it generates a libaaa.h and a libaaa.m for me. But in the .m file, there's an '@implementation libaaa'

Re: Calling a Cocoa library from C

2011-11-14 Thread Nathan Sims
On Nov 14, 2011, at 10:05 AM, Kyle Sluder wrote: The template assumes your library is going to vend Objective-C classes to apps that link against it. On Nov 14, 2011, at 10:01 AM, Jens Alfke wrote: It sounds like you are getting the library and the source files mixed up? It's the

Re: Calling a Cocoa library from C

2011-11-14 Thread Jens Alfke
On Nov 14, 2011, at 10:53 AM, Nathan Sims wrote: It's the template that threw me. It seems to me (a newb) that Xcode shouldn't provide a template when creating a Cocoa library; it doesn't really make much sense. It assumes you’re starting a new project with no code yet, and gives you an

Re: Calling a Cocoa library from C

2011-11-14 Thread Greg Parker
On Nov 12, 2011, at 2:29 AM, Jean-Daniel Dupas wrote: Le 12 nov. 2011 à 03:34, Charles Srstka a écrit : In this day and age, you should probably just use @autoreleasepool instead of NSAutoreleasePool: int get_float_data(float *result1, float *result2) { @autoreleasepool {

Re: Calling a Cocoa library from C

2011-11-14 Thread Ken Thomases
On Nov 14, 2011, at 1:22 PM, Greg Parker wrote: On Nov 12, 2011, at 2:29 AM, Jean-Daniel Dupas wrote: Le 12 nov. 2011 à 03:34, Charles Srstka a écrit : In this day and age, you should probably just use @autoreleasepool instead of NSAutoreleasePool: int get_float_data(float *result1,

Re: Calling a Cocoa library from C

2011-11-14 Thread Charles Srstka
On Nov 14, 2011, at 1:40 PM, Ken Thomases wrote: But NSAutoreleasePool doesn't drain on an exception, since it doesn't have an explicit scope. Code posted earlier in this thread used @try-@finally to explicitly drain the pool. So, while @autoreleasepool would be equivalent to a naive use

Re: Calling a Cocoa library from C

2011-11-14 Thread Ken Thomases
On Nov 14, 2011, at 3:26 PM, Charles Srstka wrote: On Nov 14, 2011, at 1:40 PM, Ken Thomases wrote: But NSAutoreleasePool doesn't drain on an exception, since it doesn't have an explicit scope. Code posted earlier in this thread used @try-@finally to explicitly drain the pool. So, while

Re: Calling a Cocoa library from C

2011-11-12 Thread Jean-Daniel Dupas
Le 12 nov. 2011 à 03:34, Charles Srstka a écrit : On Nov 11, 2011, at 8:22 PM, Wim Lewis wrote: On Nov 11, 2011, at 5:49 PM, Nathan Sims wrote: Newb question. I need to create an OS X Cocoa library that is going to be called from a C program. The C program's interface will be simple,

Re: Calling a Cocoa library from C

2011-11-12 Thread Nathan Sims
On Nov 11, 2011, at 6:22 PM, Wim Lewis wrote: int get_float_data(float *result1, float *result2) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; @try { [objcCode call]; *result1 = [more stuff]; etc.; } @catch { fprintf(stderr, omg doomed!\n); etc.; } @finally {

Re: Calling a Cocoa library from C

2011-11-12 Thread Thomas Davie
On 12 Nov 2011, at 18:45, Nathan Sims wrote: On Nov 11, 2011, at 6:22 PM, Wim Lewis wrote: int get_float_data(float *result1, float *result2) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; @try { [objcCode call]; *result1 = [more stuff]; etc.; } @catch {

Re: Calling a Cocoa library from C

2011-11-12 Thread Jens Alfke
On Nov 12, 2011, at 10:45 AM, Nathan Sims wrote: Okay, does this mean that an object instantiated by a C function has persistence across C function calls? Yes. Think of Objective-C references as pointers to opaque structs, and treat them like any other generic pointer variable. You can

Re: Calling a Cocoa library from C

2011-11-12 Thread Michael Babin
On Nov 11, 2011, at 8:34 PM, Charles Srstka wrote: On Nov 11, 2011, at 8:22 PM, Wim Lewis wrote: On Nov 11, 2011, at 5:49 PM, Nathan Sims wrote: (OSX 10.6.8, Xcode 3.2.6) int get_float_data(float *result1, float *result2) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

Re: Calling a Cocoa library from C

2011-11-12 Thread Nathan Sims
On 12 Nov 2011, at 18:45, Nathan Sims wrote: On Nov 12, 2011, at 10:56 AM, Thomas Davie wrote: Okay, does this mean that an object instantiated by a C function has persistence across C function calls? In the example above you have: [objcCode call]; I'm guessing I would have to have:

Re: Calling a Cocoa library from C

2011-11-12 Thread Jens Alfke
On Nov 12, 2011, at 12:01 PM, Nathan Sims wrote: Hmm, if not a global, where would the declaration go? The C function certainly shouldn't return it, so if it is to remain persistent across calls, wouldn't the logical (the only?) place for it be as a global in the library's .m file? Not

Re: Calling a Cocoa library from C

2011-11-12 Thread Greg Guerin
Nathan Sims wrote: Hmm, if not a global, where would the declaration go? The C function certainly shouldn't return it, so if it is to remain persistent across calls, wouldn't the logical (the only?) place for it be as a global in the library's .m file? Why shouldn't the C function

Re: Calling a Cocoa library from C

2011-11-12 Thread Thomas Davie
Note that of course you can take this one step further and use a typedef to mask that you're passing back an untyped pointer: typedef OCObjcCodeRef void * OCObjcCodeRef OCCreateObjcCode(void) { return (ObjcCodeRef)[[ObjcCode alloc] init] } int OCGetFloatData(OCObjcCodeRef objcCodeRef,

Calling a Cocoa library from C

2011-11-11 Thread Nathan Sims
Newb question. I need to create an OS X Cocoa library that is going to be called from a C program. The C program's interface will be simple, along the lines of: retval=get_float_data(float1,float2); where get_float_data() is a function that resides in the Cocoa library and invokes Objc

Re: Calling a Cocoa library from C

2011-11-11 Thread Dave DeLong
Here's a hint: What does every main() function do in every iOS and Mac app? Dave Sent from Jane On Nov 11, 2011, at 5:49 PM, Nathan Sims newsli...@autonomy.caltech.edu wrote: Newb question. I need to create an OS X Cocoa library that is going to be called from a C program. The C program's

Re: Calling a Cocoa library from C

2011-11-11 Thread Greg Parker
On Nov 11, 2011, at 5:49 PM, Nathan Sims wrote: Newb question. I need to create an OS X Cocoa library that is going to be called from a C program. The C program's interface will be simple, along the lines of: retval=get_float_data(float1,float2); where get_float_data() is a function

Re: Calling a Cocoa library from C

2011-11-11 Thread Wim Lewis
On Nov 11, 2011, at 5:49 PM, Nathan Sims wrote: Newb question. I need to create an OS X Cocoa library that is going to be called from a C program. The C program's interface will be simple, along the lines of: retval=get_float_data(float1,float2); where get_float_data() is a function

Re: Calling a Cocoa library from C

2011-11-11 Thread Charles Srstka
On Nov 11, 2011, at 8:22 PM, Wim Lewis wrote: On Nov 11, 2011, at 5:49 PM, Nathan Sims wrote: Newb question. I need to create an OS X Cocoa library that is going to be called from a C program. The C program's interface will be simple, along the lines of:

Re: Calling a Cocoa library from C

2011-11-11 Thread lbland
hi- On Nov 11, 2011, at 8:49 PM, Nathan Sims wrote: I'm unclear on how to architect this. Can a C function invoke Objc methods? yes, however you should note that: Cocoa is not Objective-C and technically you can not call Cocoa from C and expect the right thing to be done, unless ... ... if