Re: [Pyobjc-dev] Python defined type in C code
Brought to you by:
ronaldoussoren
|
From: Ronald O. <ron...@ma...> - 2010-08-31 08:02:46
|
On 30 Aug, 2010, at 15:23, Ken Brooks wrote:
> I am making a package that consists of one module written in C and two others written in Python. The C module has functions that should take parameters of a class type written in one of the Python modules. What is the most appropriate way of dealing with this? How can I "import" a Python module into my C context?
The easiest way is to define a base class in Objective-C and implement the python class as a subclass of that class:
In ObjC:
@interface MyObject : NSObject
{
}
-(id)myMethod;
@end
@implementation MyObject
// No method implementation here
@end
In Python:
class MyRealObject (objc.lookUpClass("MyObject")):
def myMethod(self):
print "Doing it"
Then design the C API to accept instances of the ObjC base class. The primary advantage of this approach is that this gets you the right prototypes in the C code.
BTW. All of this assumes that you're using PyObjC and that your "C" code is actually Objective-C.
Ronald
>
> Ken
> ------------------------------------------------------------------------------
> Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
> Be part of this innovative community and reach millions of netbook users
> worldwide. Take advantage of special opportunities to increase revenue and
> speed time-to-market. Join now, and jumpstart your future.
> http://p.sf.net/sfu/intel-atom-d2d_______________________________________________
> Pyobjc-dev mailing list
> Pyo...@li...
> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev
|