python - How can I call objective-c from cython? -


cython can write c code, , can cross compile ios;

using pyobjus can call objective-c code, running on osx, not on ios, because python can't import _ctypes.

i know kivy can call coregraphices.framework via cython.

kivy/core/image/img_imageio.pyx

cdef extern "coregraphics/cgdataprovider.h":     ctypedef void *cfdataref                          unsigned char *cfdatagetbyteptr(cfdataref)         ctypedef struct cgpoint:                              float x                                           float y                                        ctypedef struct cgsize:                               float width                                       float height                                   ctypedef struct cgrect:                               cgpoint origin                                    cgsize size                                    cgrect cgrectmake(float, float, float, float) 

this objective-c code

pyobjc.h

#import <foundation/foundation.h> @interface pyobjc : nsobject -(char *)send:(nsstring *)message; -(char *)recv; @property(nonatomic, strong) nsmutablearray *messagequeue; @end 

pyobjc.m

#import "pyobjc.h" @implementation pyobjc -(id)init{ nslog(@"init"); self.messagequeue = [[nsmutablearray alloc] init]; return self; }  -(char *)send:(nsstring *)message{ nslog(@"send: %@", message); [self.messagequeue addobject:message]; return [message utf8string]; }  -(char *)recv{ nsstring *stringback = [self.messagequeue objectatindex:0]; nslog(@"recv: %@",stringback); [self.messagequeue removeobjectatindex:0]; return [stringback utf8string]; } @end 

img_ble.pyx

cdef extern "ble/pyobjc.h":                    ctypedef char *pyobjcref                        char *pysend(pyobjcref pyoc, char *message)     char *pyrecv(pyobjcref pyoc)                 def send():                                         cdef pyobjcref pychar                           p = send("hello python")                        pychar = p                                   def recv():                                         cdef pyobjcref pchar                            p = recv()                                      pchar = p  

but can't cross compile ios

building 'kivy.core.image.img_ble' extension     /applications/xcode.app/contents/developer/platforms/iphoneos.platform/developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2 -dndebug -g -o3 -wall -wstrict-prototypes -march=armv7 -mcpu=arm176jzf -mcpu=cortex-a8 -pipe -no-cpp-precomp -miphoneos-version-min=6.1 -o3 -g -i/applications/xcode.app/contents/developer/platforms/iphoneos.platform/developer/sdks/iphoneos6.1.sdk -i/users/ygmpkk/documents/source_learn/kivy-ios/tmp/python-2.7.1/include -i/users/ygmpkk/documents/source_learn/kivy-ios/tmp/python-2.7.1 -c kivy/core/image/img_ble.c -o build/temp.macosx-10.8-x86_64-2.7/kivy/core/image/img_ble.o -isysroot /applications/xcode.app/contents/developer/platforms/iphoneos.platform/developer/sdks/iphoneos6.1.sdk     in file included /applications/xcode.app/contents/developer/platforms/iphoneos.platform/developer/sdks/iphoneos6.1.sdk/system/library/frameworks/foundation.framework/headers/foundation.h:8,                      kivy/core/image/ble/pyobjc.h:9,                      kivy/core/image/img_ble.c:254:     /applications/xcode.app/contents/developer/platforms/iphoneos.platform/developer/sdks/iphoneos6.1.sdk/system/library/frameworks/foundation.framework/headers/nsobjcruntime.h:409: error: stray ‘@’ in program     /applications/xcode.app/contents/developer/platforms/iphoneos.platform/developer/sdks/iphoneos6.1.sdk/system/library/frameworks/foundation.framework/headers/nsobjcruntime.h:409: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘nsstring’     /applications/xcode.app/contents/developer/platforms/iphoneos.platform/developer/sdks/iphoneos6.1.sdk/system/library/frameworks/foundation.framework/headers/nsobjcruntime.h:411: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token     /applications/xcode.app/contents/developer/platforms/iphoneos.platform/developer/sdks/iphoneos6.1.sdk/system/library/frameworks/foundation.framework/headers/nsobjcruntime.h:412: error: expected ‘)’ before ‘*’ token     /applications/xcode.app/contents/developer/platforms/iphoneos.platform/developer/sdks/iphoneos6.1.sdk/system/library/frameworks/foundation.framework/headers/nsobjcruntime.h:414: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token     /applications/xcode.app/contents/developer/platforms/iphoneos.platform/developer/sdks/iphoneos6.1.sdk/system/library/frameworks/foundation.framework/headers/nsobjcruntime.h:415: error: expected ‘)’ before ‘*’ token     /applications/xcode.app/contents/developer/platforms/iphoneos.platform/developer/sdks/iphoneos6.1.sdk/system/library/frameworks/foundation.framework/headers/nsobjcruntime.h:417: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token     /applications/xcode.app/contents/developer/platforms/iphoneos.platform/developer/sdks/iphoneos6.1.sdk/system/library/frameworks/foundation.framework/headers/nsobjcruntime.h:418: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token     /applications/xcode.app/contents/developer/platforms/iphoneos.platform/developer/sdks/iphoneos6.1.sdk/system/library/frameworks/foundation.framework/headers/nsobjcruntime.h:422: error: expected ‘)’ before ‘*’ token     /applications/xcode.app/contents/developer/platforms/iphoneos.platform/developer/sdks/iphoneos6.1.sdk/system/library/frameworks/foundation.framework/headers/nsobjcruntime.h:423: error: expected ‘)’ before ‘*’ token     in file included /applications/xcode.app/contents/developer/platforms/iphoneos.platform/developer/sdks/iphoneos6.1.sdk/system/library/frameworks/foundation.framework/headers/nsobject.h:6,                      /applications/xcode.app/contents/developer/platforms/iphoneos.platform/developer/sdks/iphoneos6.1.sdk/system/library/frameworks/foundation.framework/headers/nsarray.h:5,                      /applications/xcode.app/contents/developer/platforms/iphoneos.platform/developer/sdks/iphoneos6.1.sdk/system/library/frameworks/foundation.framework/headers/foundation.h:10, 

your compiler didn't detected code want compile objective-c. can:

  1. rename generated cython file .c .m
  2. or, make .h objective-c free, ie, create c method , hide objective-c complexity .m of library only.
  3. or, pybojus directly?

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -