Re: [Pyobjc-dev] Calling Objective-C++ code
Brought to you by:
ronaldoussoren
From: Ronald O. <ron...@ma...> - 2014-07-22 06:56:23
|
On 22 Jul 2014, at 07:14, Douglas Roark <jo...@vt...> wrote: > Hello. I'd like to request a little help. I'm trying to taking some > Objective-C++ code and call it from Python. I seem to be stuck and > could use a little help getting out of the proverbial mud. > > I'm new to ObjC and am trying to figure out how to get a feature > working. There's some ObjC++ code that's already written and can > probably be used after making a few mods. The ObjC++ code basically > uses C++-style headers, although one includes a "signals:" section > (i.e., it's not pure C++). The underlying .mm code is your standard > C++/ObjC mix. My initial thought was that I could use PyObjC to call > the ObjC++ code from Python. The more I look into it, though, the more > I think PyObjC may not be able to create a bridge as-is; pure ObjC > code seems to be necessary. I don't think SWIG or SIP are able to > handle ObjC++ either. This leads me to believe that I'll have to > rewrite the ObjC++ code in pure ObjC and then call it from PyObjC (or > maybe, if it's possible, just rewrite the header files). I have a > couple of questions before I go much further. > > -Is my understanding correct? In other words, is PyObjC unable to > handle to handle such headers? (See > https://github.com/bitcoin/bitcoin/blob/0.9.2/src/qt/macdockiconhandler.h > for one such header I'm trying to use.) PyObjC doesn’t use the header files at all, except for a side project that reads header files an generates some optional definitions from them. That tool is very picky, too picky even, in what it accepts and likely wouldn’t work even if the header wasn’t Objective-C++. The PyObjC core reads information about classes and methods using the Objective-C runtime API, generally that information is enough to access Objective-C code from Python. That should also work for Objective-C++ code, as long as you only try to use Objective-C classes (the @interface stuff) and don’t use C++ classes in method signatures (so no methods that return a vector<int>). Looking at the header you mention: that won’t work with PyObjC, that’s basically pure C++ code with small bits of Objective-C sprinkled in. With some luck SIP might be able to wrap this class, its API appears to be completely in C++. You may have to tweak the headers a bit to ensure that the “Objective-“ definitions aren’t visible to SIP’s scanner, but other than that it should work. That said: I’ve never used SIP myself. > -Is it possible to mix-and-match ObjC header files with C++-style > definitions in the implementation (i.e., can I rewrite only the header > files)? My gut says this isn't possible. That’s not a problem, again: as long as you don’t use C++ classes in method signatures. Ronald > -If I'm incorrect, and PyObjC can call this code, are there any > examples or douments online? I think I have a good idea of how to call > the ObjC code, just not any potential ObjC++ code. > > Thanks in advance for any help you can give! > > Doug > > ------------------------------------------------------------------------------ > Want fast and easy access to all the code in your enterprise? Index and > search up to 200,000 lines of code with a free copy of Black Duck > Code Sight - the same software that powers the world's largest code > search on Ohloh, the Black Duck Open Hub! Try it now. > http://p.sf.net/sfu/bds > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev |