Cython
会写C
代码,并且cross compile
可以iOS
;
使用Pyobjus
can 调用Objective-C
代码,但仅用于运行 on OSX
,而不是 on iOS
,因为 python 不能import _ctypes
。
我知道kivy
可以CoreGraphices.Framework
通过Cython
.
kivy/core/image/img_imageio.pyx
cdef extern from "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)
这是我的objective-c
代码
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 from "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
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 from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:8,
from kivy/core/image/ble/pyobjc.h:9,
from 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 from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:6,
from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSArray.h:5,
from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:10,