Download - MobiRuby introduction
![Page 1: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/1.jpg)
MobiRubyiOS + Ruby = Super Awesome!!
![Page 2: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/2.jpg)
Hi! I’m masuidrive.
• Yuichiro MASUI (masuidrive, Ichi)
• Open source developer, Ruby fun
• FrogApps, Inc. ex-Appcelerati
• Pukiwiki, Ruby on Rails tutorial movie in Japanese, IKEA hacker
• Furo-grammer (Coding in hot tub)
![Page 3: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/3.jpg)
What’s MobiRuby?
• iOS app development environment on mruby
• Can access native functions
• Have plan for Android version
![Page 4: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/4.jpg)
Demo Apps
• MobiRuby Game
![Page 5: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/5.jpg)
Vision
• MobiRuby provides Ruby power to Mobile devices
• DSL is most important Ruby power
![Page 6: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/6.jpg)
How you can get it
• http://mobiruby.org/
• It’s initial and truly ALPHA version, so it’s for only mruby and iOS hackers.
![Page 7: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/7.jpg)
MobiRuby stack
iOS
mruby
mruby-cfunc
Your code
mruby-cocoa
mobiruby-common
mobiruby-ios
![Page 8: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/8.jpg)
MobiRuby stack
iOS
mruby
mruby-cfunc
Your code
mruby-cocoa
mobiruby-common
mobiruby-ios
![Page 9: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/9.jpg)
mruby
• New implementation of Ruby for embedding
• Built by dad Matz
• Less memory and storage
• Not required POSIX, only C99
• Simple spec, Not included File, Socket, Thread and ext libraries
![Page 10: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/10.jpg)
![Page 11: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/11.jpg)
MobiRuby stack
iOS
mruby
mruby-cfunc
Your code
mruby-cocoa
mobiruby-common
mobiruby-ios
![Page 12: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/12.jpg)
mruby-cfunc
• C function bridge for mruby
• Call C based function directly
• Based on libFFI
• Like DL library on CRuby
![Page 13: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/13.jpg)
mruby-cfunc
str = "STRING"
CFunc::call(CFunc::Void, "puts", str)
STRING
![Page 14: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/14.jpg)
mruby-cfunc
str = "STRING"
ptr = CFunc::Pointer.malloc(7)
result_ptr = CFunc::call(CFunc::Pointer, "strcpy", ptr, str)
ptr.to_s
-‐> “STRING”
![Page 15: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/15.jpg)
mruby-cfunc
\
class TestStruct < CFunc::Struct define CFunc::SInt8, :x, CFunc::SInt16, :yend
test = TestStruct.newtest[:x] = 10
![Page 16: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/16.jpg)
MobiRuby stack
iOS
mruby
mruby-cfunc
Your code
mruby-cocoa
mobiruby-common
mobiruby-ios
![Page 17: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/17.jpg)
mruby-cocoa• Cocoa bridge for mruby
• Use Cocoa functions transparently
• Based on mruby-cfunc and Cocoa runtime
• Manipulate Cocoa objects
• Create class/instance, inherit existing classes
• Garbage collection
![Page 18: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/18.jpg)
Bridge Cocoa runtime
• Objective-C has powerful runtime features
• Create and modify class dynamically
• ObjC class <- Ruby class <- ObjC class
• ObjC value interconverted with Ruby value
• Supported delegate and blocks
![Page 19: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/19.jpg)
Memory management
• Objective-C - Reference count
• mruby - Mark & Sweep
• Swizzled Objective-C release method
![Page 20: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/20.jpg)
Multi-threading
• MobiRuby does not support threads
• Because mruby does not support threads
• I have not touched them yet
• Need to implement multi VM instead of thread
![Page 21: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/21.jpg)
MobiRuby stack
iOS
mruby
mruby-cfunc
Your code
mruby-cocoa
mobiruby-common
mobiruby-ios
![Page 22: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/22.jpg)
mobiruby-ios
• iOS specific utilities
• Bootstrap
• Xcode integration
• Wrapped classes
![Page 23: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/23.jpg)
Wrapped Audio Playerclass AudioPlayer def initialize(filename) name, ext = filename.split(".") path = Cocoa::NSBundle._mainBundle. _pathForResource name, :ofType, ext url = Cocoa::NSURL._fileURLWithPath path @avap = Cocoa::AVAudioPlayer._alloc. _initWithContentsOfURL url, :error, nil end
def play; @avap._play; endend
AudioPlayer.new("bgm00.wav").play
![Page 24: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/24.jpg)
MobiRuby stack
iOS
mruby
mruby-cfunc
Your code
mruby-cocoa
mobiruby-common
mobiruby-ios
![Page 25: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/25.jpg)
mobiruby-common
• Will be common utilities with Android ver.
• require method
• Some POSIX based functions
![Page 26: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/26.jpg)
MobiRuby stack
iOS
mruby
mruby-cfunc
Your code
mruby-cocoa
mobiruby-common
mobiruby-ios
![Page 27: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/27.jpg)
Your code
class Cocoa::MyAlertView < Cocoa::UIAlertView define C::Void, :alertView, Cocoa::Object, :clickedButtonAtIndex, C::Int do |me, index| if index.to_i == 1 app = Cocoa::UIApplication._sharedApplication str = "http://mobiruby.org" url = Cocoa::NSURL._URLWithString(str) app._openURL url end endend
![Page 28: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/28.jpg)
Your code
alert = Cocoa::MyAlertView._alloc._initWithTitle "Hello", :message, "I am MobiRuby", :delegate, nil, :cancelButtonTitle, "I know!", :otherButtonTitles, "What's?", nil
alert._setDelegate alertalert._show
![Page 29: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/29.jpg)
Road map
• Finished building Cocoa bridge
• Fix bugs, Improvement
• Packaging
• Documentation
• Build wrapped APIs
![Page 30: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/30.jpg)
Road map
• Finished building Cocoa bridge
• Fix bugs, Improvement
• Packaging
• Documentation
• Build wrapped APIs
![Page 31: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/31.jpg)
Road map
• Finished building Cocoa bridge
• Fix bugs, Improvement
• Packaging
• Documentation
• Build wrapped APIs
Version 1Q1 2013
![Page 32: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/32.jpg)
Progress in Sept 2012
• Already MobiRuby based app is in AppStore
• Finally released alpha 1
• It's only for iOS and mruby hackers
• Need deeply understanding Cocoa runtime, mruby, Garbage collection
![Page 33: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/33.jpg)
Current tasks
• Fixed crashing bugs and memory leaks
• Test Test Test!!!
• Support `long` and `long long`, define Cocoa property and more...
• Circular reference
• mruby stability
![Page 34: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/34.jpg)
What’s difference?
• RubyMotion
• Rhodes
• Ruboto
• RubyCocoa
• Titanium Mobile
![Page 35: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/35.jpg)
What’s difference?
• RubyMotion
• Rhodes
• Ruboto
• RubyCocoa
• Titanium Mobile
Diversity is Good
![Page 36: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/36.jpg)
Pros.
• Ruby power
• Based on Matz implemented Ruby
• MIT license
• Compact (~3000 lines)
• An unexplored field
![Page 37: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/37.jpg)
Cons.
• Buggy
• Less classes / functions
• Don't have debugging feature
• Need to understand iOS and Cocoa
![Page 38: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/38.jpg)
FAQ
• Can I use RubyGems?
• Can I use meta programming?e.g., define_method, eval
• Can I use exists Cocoa libraries?
• Can I define new method to exist Cocoa class?
• What version iOS does it support?
![Page 39: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/39.jpg)
Can I use RubyGems?
• No, mruby doesn’t have compatibility with CRuby ext. APIs.
• You need to write new extension for mruby
![Page 40: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/40.jpg)
Can I use meta programming?e.g., define_method, eval
• Yes, mruby supports almost all dynamic programming features.
• But MobiRuby doesn’t support eval. mruby can remove compiler. (it’s for Apple)
![Page 41: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/41.jpg)
Can I use existing Cocoa libraries?
• Yes, you can use almost all existing libraries.
• I think CocoaPods will be a good partner
![Page 42: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/42.jpg)
Can I define new method to exist Cocoa class?
• Yes, You can define new methods from Ruby
• You can inherit exists Cocoa and create new class from Ruby
![Page 43: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/43.jpg)
What version iOS does it support?
• MobiRuby supports iOS4 and higher version.
• I tested on iOS4 and iOS5. Probably run on iOS6.
![Page 44: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/44.jpg)
Wanted contributions
• Here’s your big chance!
• Need understanding C/Objective-C and iOS development
• Owned OSX and iOS developer license
![Page 45: MobiRuby introduction](https://reader033.vdocument.in/reader033/viewer/2022051816/544f4ca3b1af9f2f638b575a/html5/thumbnails/45.jpg)
Thank you
• Logo design: Maylis Agniel
• http://mobiruby.org
• http://fb.me/mobiruby
• http://twitter.com/mobiruby
• http://github.com/mobiruby