On 19 Feb, 2008, at 10:32, James Trankelson wrote:
> Hello,
>
> I'm trying to augment my existing ObjectiveC application with some
> embedded Python. I've got an embedded Python interpreter that can run
> PyObjC, but what I would like to do is the following:
>
> In my ObjectiveC application, I'd like to get a pointer to an object
> (an NSString, for example):
>
> NSString *tmpStr = [NSString stringWithString:@"Test"];
>
> Then, I would like to pass this NSString pointer to a Python function,
> so that I can use PyObjC to operate on the object in the normal PyObjC
> fashion:
>
> def handler(s):
> print "The length of the string is ", s.length()
>
> I would try to call the Python handler() procedure like so:
>
> PyObject* arg; // tmpStr
> PyObject* method; // "handler"
> PyObject_CallMethodObjArgs(_self , method, arg, NULL);
>
> I don't know how to go about obtaining PyObject*s from the
> ObjectiveC types...
>
> Is this even possible?
That's not impossible, but not the easiest way to do this. What I'd do
is to define an (abstract) baseclass in Objective-C that defines the
methods you want to call, use PyObjC to create a Python subclass of
that baseclass which actually implements the functionality and then
call those methods using normal Objective-C method calls. That way you
don't have to write code to convert data from Objective-C to Python
and back.
Ronald
>
>
> Thanks.
>
> -jim t
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Pyobjc-dev mailing list
> Pyo...@li...
> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev
|