Skip to content

Instantly share code, notes, and snippets.

@Watson1978
Created March 24, 2012 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Watson1978/2178472 to your computer and use it in GitHub Desktop.
Save Watson1978/2178472 to your computer and use it in GitHub Desktop.
MacRuby : ticket #1485
require "mkmf"
$CFLAGS << ' -fobjc-gc -std=c99 '
create_makefile("Foo")
#import <Foundation/Foundation.h>
#include <stdarg.h>
@interface Foo : NSObject {
}
/// this method would print the variables.
- (void) log: (id) firstObj, ... NS_REQUIRES_NIL_TERMINATION; // Obj-C variadic method. Using nil at the end of args.
@end
#include "foo.h"
@implementation Foo
- (void) log: (id) firstObj, ... {
va_list ap;
va_start (ap, firstObj);
for (id obj = firstObj; obj != nil; obj = va_arg(ap, id) ){
NSLog(@"%@", obj);
}
va_end (ap);
}
@end
// For MacRuby
void Init_Foo() {}
require 'Foo'
load_bridge_support_file 'Foo.bridgesupport'
Foo.new.log ("1", "2", "3", nil)
@Watson1978
Copy link
Author

$ macruby extconf.rb 
$ make
$ gen_bridge_metadata -c '-I.' foo.h > Foo.bridgesupport

$ macruby test.rb
2012-03-24 14:07:54.778 macruby[14022:507] 1
2012-03-24 14:07:54.780 macruby[14022:507] 2
2012-03-24 14:07:54.781 macruby[14022:507] 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment