Created
October 15, 2008 15:50
-
-
Save snaka/16938 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# AppController.rb | |
# test | |
require 'osx/cocoa' | |
OSX.ns_import :MyObject | |
class AppController < OSX::NSObject | |
include OSX | |
def initialize | |
@tester = MyObject.alloc.init; | |
end | |
# Objective-Cのメソッドを呼び出し | |
def doTest(sender) | |
puts "doTest:" | |
@tester.methodA_from(false, self) | |
end | |
ib_action :doTest | |
# Objective-C側から呼び出してもらうコールバックメソッド | |
objc_method :callback, [:BOOL, :BOOL] | |
def callback(para) | |
puts "callback:" | |
puts "para is #{para}" | |
puts "callback return <false>" | |
return false | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MyObject.h | |
// test | |
#import <Cocoa/Cocoa.h> | |
@interface MyObject : NSObject { | |
} | |
- (void)methodA:(bool)param from:(id)caller; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MyObject.m | |
// test | |
#import "MyObject.h" | |
@implementation MyObject : NSObject | |
- (void)methodA:(bool)param from:(id)caller | |
{ | |
NSLog(@"*** Call from RubyCocoa > param: %d", param); | |
BOOL ret = [caller callback:false]; | |
NSLog(@"*** callback returned [%d]", ret); | |
if (ret) { | |
NSLog(@"*** callback returned <TRUE>"); | |
} | |
else { | |
NSLog(@"*** callback returned <FALSE>"); | |
} | |
return; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment