Cocoa
我在http://www.rforge.net/Cocoa/找到了 R 包,我想用它来调用我定制的 Objective-c 类。
我试图加载一个包含一个简单自定义类(DOHello
如下所示)的 dylib,然后调用:
hc <- .MClass("DOHello")
h <- .M(hc, "alloc")
h <- .M(h, "init")
.M(h, "hello")
前三行代码没问题,但是当我调用 时.M(h, "hello")
,整个 RStudio 会话崩溃。我也试过直接把源码DOHello
加到Cocoa
包里,结果是一样的。
班级DOHello
:
@interface DOHello : NSObject
- (void)hello;
@end
@implementation DOHello
- (void)hello {
printf("Hey, there");
}
@end
崩溃报告:
Process: rsession [8215]
Path: /Applications/RStudio.app/Contents/MacOS/rsession
Identifier: rsession
Version: ???
Code Type: X86-64 (Native)
Parent Process: RStudio [1931]
User ID: 502
Date/Time: 2013-03-04 11:47:44.858 +0800
OS Version: Mac OS X 10.8.2 (12C54)
Report Version: 10
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 com.apple.CoreFoundation 0x00007fff867d301d __NSI0 + 621
1 com.apple.CoreFoundation 0x00007fff867d2aee -[NSInvocation getArgument:atIndex:] + 302
2 Cocoa.so 0x000000010c4fef4f ObjCsendMsg + 1135
3 libR.dylib 0x0000000109ffee37 do_External + 327 (dotcode.c:540)
4 libR.dylib 0x000000010a02e448 Rf_eval + 1672 (eval.c:494)
5 libR.dylib 0x000000010a02fedd do_begin + 141 (eval.c:1415)
6 libR.dylib 0x000000010a02e29c Rf_eval + 1244 (eval.c:468)
7 libR.dylib 0x000000010a0333b1 Rf_applyClosure + 849 (eval.c:861)
8 libR.dylib 0x000000010a02e1b2 Rf_eval + 1010 (eval.c:512)
9 libR.dylib 0x000000010a0669e2 Rf_ReplIteration + 514 (main.c:256)
10 libR.dylib 0x000000010a066cd1 R_ReplConsole + 161 (main.c:306)
11 libR.dylib 0x000000010a0671ea run_Rmainloop + 90 (main.c:988)
12 rsession 0x0000000109786b1b r::session::runEmbeddedR(core::FilePath const&, core::FilePath const&, bool, bool, SA_TYPE, r::session::Callbacks const&, r::session::InternalCallbacks*) + 427
13 rsession 0x0000000109769b29 r::session::run(r::session::ROptions const&, r::session::RCallbacks const&) + 3193
14 rsession 0x0000000109386f35 main + 14517
15 rsession 0x000000010936e154 start + 52
崩溃报告不完整,我只是复制了我认为有用的部分。