🕷 zenspider.com

by ryan davis



sitemap
Looking for the Ruby Quickref?

Inline::ObjC

Published 2005-12-14 @ 04:16

Tagged rubyinline, ruby

Nuno Cruces provided me the following gem (hacked up by yours truly):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require 'inline'

class Inline::ObjC < Inline::C
  def initialize(mod)
    super(mod)
  end

  def import(header)
    @src << "#import #{header}"
  end
end

class MyClass
  inline(:ObjC) do |builder|
    builder.import "<Foundation/NSString.h>"
    builder.add_compile_flags '-x objective-c', '-framework Foundation'

    builder.c %q{
      void test() {
        printf("%s\n", [@"Hello World!" cString]);
      }
    }
  end
end

MyClass.new.test

I love it… OSX hackers, have at it…