Inline::ObjC

| | Comments (0)
Nuno Cruces provided me the following gem (hacked up by yours truly):
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...

Leave a comment