Contenu connexe Similaire à Macruby& Hotcocoa presentation by Rich Kilmer Similaire à Macruby& Hotcocoa presentation by Rich Kilmer (20) Plus de Matt Aimonetti (9) Macruby& Hotcocoa presentation by Rich Kilmer2. A History of Apple and Ruby
MacRuby
2002 2003 2004 2005 2006 2007 2008 2009
OS X 10.5 OS X 10.x
OS X 10.2 OS X 10.4
Ruby 1.8.6 Ruby 1.8.7
Ruby 1.6.7 Ruby 1.8.2
RubyGems RubyGems
RubyCocoa RubyCocoa
Rails Rails 2.2
4. Apple’s Goals:
t
s
e
b
e
h class
t
Make Ruby a first
Cocoa programming language
on Mac OS X
5. Mac OS X Stack
User Experience
Application Frameworks
Graphics and Media
Darwin
6. Mac OS X Stack - Languages
User Experience Objective-C
Application Frameworks
Graphics and Media
Darwin C
7. Bridging Ruby & Objective-C
RubyCocoa
by
by FUJIMOTO Hisakuni (2001)
Bundled with Mac OS X 10.5 (stable)
8. RubyCocoa Hello World
require 'osx/cocoa'; include OSX
app = NSApplication.sharedApplication
win = NSWindow.alloc.initWithContentRect_styleMask_backing_defer(
[0, 0, 200, 60],
NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask,
NSBackingStoreBuffered,
false)
win.title = 'Hello World'
button = NSButton.alloc.initWithFrame(NSZeroRect)
win.contentView.addSubview(button)
button.bezelStyle = NSRoundedBezelStyle
button.title = 'Hello!'
button.sizeToFit
button.frameOrigin = NSMakePoint((win.contentView.frameSize.width / 2.0) - (button.frameSize.width / 2.0),
(win.contentView.frameSize.height / 2.0) - (button.frameSize.height / 2.0))
button_controller = Object.new
def button_controller.sayHello(sender)
puts quot;Hello World!quot;
end
button.target = button_controller
button.action = 'sayHello:'
win.display
win.orderFrontRegardless
app.run
10. Enter MacRuby
MacRuby 0.4
Objective-C 2.0 Ruby 1.9
Core Garbage Standard
Runtime YARV Parser
Foundation Collector Library
Garbage Built-ins
Collector
Every Ruby class is an Objective-C class
Every Ruby object is an Objective-C object
Every Ruby method is an Objective-C method
11. MacRuby Hello World
framework ‘Cocoa’
app = NSApplication.sharedApplication
win = NSWindow.alloc.initWithContentRect([0, 0, 200, 60],
styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask,
backing:NSBackingStoreBuffered,
defer:false)
win.title = 'Hello World'
button = NSButton.alloc.initWithFrame(NSZeroRect)
win.contentView.addSubview(button)
button.bezelStyle = NSRoundedBezelStyle
button.title = 'Hello!'
button.sizeToFit
button.frameOrigin = NSMakePoint((win.contentView.frameSize.width / 2.0) - (button.frameSize.width / 2.0),
(win.contentView.frameSize.height / 2.0) - (button.frameSize.height / 2.0))
button_controller = Object.new
def button_controller.sayHello(sender)
puts quot;Hello World!quot;
end
button.target = button_controller
button.action = 'sayHello:'
win.display
win.orderFrontRegardless
app.run
12. Enter HotCocoa
HotCocoa is an idiomatic
Ruby API that simplifies the
configuration and wiring
together of ObjC/Cocoa classes
13. MacRuby Hello World
framework ‘Cocoa’
app = NSApplication.sharedApplication
win = NSWindow.alloc.initWithContentRect([0, 0, 200, 60],
styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask,
backing:NSBackingStoreBuffered,
defer:false)
win.title = 'Hello World'
button = NSButton.alloc.initWithFrame(NSZeroRect)
win.contentView.addSubview(button)
button.bezelStyle = NSRoundedBezelStyle
button.title = 'Hello!'
button.sizeToFit
button.frameOrigin = NSMakePoint((win.contentView.frameSize.width / 2.0) - (button.frameSize.width / 2.0),
(win.contentView.frameSize.height / 2.0) - (button.frameSize.height / 2.0))
button_controller = Object.new
def button_controller.sayHello(sender)
puts quot;Hello World!quot;
end
button.target = button_controller
button.action = 'sayHello:'
win.display
win.orderFrontRegardless
app.run
14. HotCocoa Hello World
require ‘hotcocoa’; include HotCocoa
app = NSApplication.sharedApplication
win = NSWindow.alloc.initWithContentRect([0, 0, 200, 60],
styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask,
backing:NSBackingStoreBuffered,
defer:false)
win.title = 'Hello World'
button = NSButton.alloc.initWithFrame(NSZeroRect)
win.contentView.addSubview(button)
button.bezelStyle = NSRoundedBezelStyle
button.title = 'Hello!'
button.sizeToFit
button.frameOrigin = NSMakePoint((win.contentView.frameSize.width / 2.0) - (button.frameSize.width / 2.0),
(win.contentView.frameSize.height / 2.0) - (button.frameSize.height / 2.0))
button_controller = Object.new
def button_controller.sayHello(sender)
puts quot;Hello World!quot;
end
button.target = button_controller
button.action = 'sayHello:'
win.display
win.orderFrontRegardless
app.run
15. HotCocoa Hello World
require ‘hotcocoa’; include HotCocoa
app = NSApplication.sharedApplication
win = window :title => ‘hello world’, :frame => [0, 0, 200, 60]
button = NSButton.alloc.initWithFrame(NSZeroRect)
win.contentView.addSubview(button)
button.bezelStyle = NSRoundedBezelStyle
button.title = 'Hello!'
button.sizeToFit
button.frameOrigin = NSMakePoint((win.contentView.frameSize.width / 2.0) - (button.frameSize.width / 2.0),
(win.contentView.frameSize.height / 2.0) - (button.frameSize.height / 2.0))
button_controller = Object.new
def button_controller.sayHello(sender)
puts quot;Hello World!quot;
end
button.target = button_controller
button.action = 'sayHello:'
win.display
win.orderFrontRegardless
app.run
16. HotCocoa Hello World
require ‘hotcocoa’; include HotCocoa
app = NSApplication.sharedApplication
win = window :title => ‘hello world’, :frame => [0, 0, 200, 60]
b = button :title => ‘Hello!’, :layout => {:align => :center}
win << b
button_controller = Object.new
def button_controller.sayHello(sender)
puts quot;Hello World!quot;
end
button.target = button_controller
button.action = 'sayHello:'
win.display
win.orderFrontRegardless
app.run
17. HotCocoa Hello World
require ‘hotcocoa’; include HotCocoa
app = NSApplication.sharedApplication
win = window :title => ‘hello world’, :frame => [0, 0, 200, 60]
b = button :title => ‘Hello!’, :layout => {:align => :center}
win << b
b.on_action { puts “Hello World!” }
win.display
win.orderFrontRegardless
app.run
18. HotCocoa Hello World
require ‘hotcocoa’; include HotCocoa
application do
win = window :title => ‘hello world’, :frame => [0, 0, 200, 60]
b = button :title => ‘Hello!’, :layout => {:align => :center}
win << b
b.on_action { puts “Hello World!” }
end
20. hotcocoa <app> Rakefile
config
build.yml
lib
menu.rb
lib
application.rb
resources
HotCocoa.icns
22. MacRuby Experimental
MacRuby 0.5
LLVM Objective-C 2.0 Ruby 1.9
Garbage Standard
JIT Runtime YARV Parser
Collector Library
Disk/Socket Core Garbage
AOT Built-ins
IO Foundation Collector
Numerous optimizations (speed!)
No libffi for external calls, new bridgesupport
Passing many RubySpecs already!
Will implement fully concurrent threading