我试图使用Python中的Objective-C类来实现这一点,但是Objective-C不能调用调用Python函数的方法。在
以下是Objective-C代码的框架代码:
//
// scalelib.h
// Scalelib Cocoa Framework
//
// Created by Matthew Mitchell on 04/07/2010.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface Game : NSObject {
id current_pyfunc;
}
-(void) addPyFunc: (id) pyfunc;
-(void) callPyFunc;
@end
//
// scalelib.m
// Scalelib Cocoa Framework
//
// Created by Matthew Mitchell on 04/07/2010.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "Game.h"
@implementation Game
-(void) addPyFunc: (id) pyfunc{
current_pyfunc = pyfunc;
}
-(void) callPyFunc{
[current_pyfunc call]; //Segmentation fault. Method doesn't exist for some reason.
}
@end
下面是一个python脚本,它加载框架并在失败的情况下测试回调的使用。在
^{pr2}$我得到输出:
九 分段故障
分段错误是因为python中的call方法显然不存在。那么我如何使它存在于Objective-C中呢?在
即使代码真的起作用了也没用,但我现在只是在测试。一旦回调生效,我就可以为python创建库了。在
谢谢你的帮助。在
我猜是保留数。在
您不会保留传递给addPyFunc的create_callback()的结果
因此,在你调用它之前,它可能会被垃圾收集掉。在
相关问题 更多 >
编程相关推荐