Slide 1

Slide 1 text

MobiRuby iOS + Ruby = Super Awesome!!

Slide 2

Slide 2 text

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)

Slide 3

Slide 3 text

What’s MobiRuby? • iOS app development environment on mruby • Can access native functions • Have plan for Android version

Slide 4

Slide 4 text

Demo Apps • MobiRuby Game

Slide 5

Slide 5 text

Vision • MobiRuby provides Ruby power to Mobile devices • DSL is most important Ruby power

Slide 6

Slide 6 text

How you can get it • http://mobiruby.org/ • It’s initial and truly ALPHA version, so it’s for only mruby and iOS hackers.

Slide 7

Slide 7 text

MobiRuby stack iOS mruby mruby- cfunc Your code mruby- cocoa mobiruby- common mobiruby- ios

Slide 8

Slide 8 text

MobiRuby stack iOS mruby mruby- cfunc Your code mruby- cocoa mobiruby- common mobiruby- ios

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

MobiRuby stack iOS mruby mruby- cfunc Your code mruby- cocoa mobiruby- common mobiruby- ios

Slide 12

Slide 12 text

mruby-cfunc • C function bridge for mruby • Call C based function directly • Based on libFFI • Like DL library on CRuby

Slide 13

Slide 13 text

mruby-cfunc str  =  "STRING" CFunc::call(CFunc::Void,  "puts",  str) STRING

Slide 14

Slide 14 text

mruby-cfunc str  =  "STRING" ptr  =  CFunc::Pointer.malloc(7) result_ptr  =  CFunc::call(CFunc::Pointer,   "strcpy",  ptr,  str) ptr.to_s -­‐>  “STRING”

Slide 15

Slide 15 text

mruby-cfunc \ class  TestStruct  <  CFunc::Struct        define  CFunc::SInt8,    :x,                      CFunc::SInt16,  :y end test  =  TestStruct.new test[:x]  =  10

Slide 16

Slide 16 text

MobiRuby stack iOS mruby mruby- cfunc Your code mruby- cocoa mobiruby- common mobiruby- ios

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Memory management • Objective-C - Reference count • mruby - Mark & Sweep • Swizzled Objective-C release method

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

MobiRuby stack iOS mruby mruby- cfunc Your code mruby- cocoa mobiruby- common mobiruby- ios

Slide 22

Slide 22 text

mobiruby-ios • iOS specific utilities • Bootstrap • Xcode integration • Wrapped classes

Slide 23

Slide 23 text

Wrapped Audio Player class  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;  end end AudioPlayer.new("bgm00.wav").play

Slide 24

Slide 24 text

MobiRuby stack iOS mruby mruby- cfunc Your code mruby- cocoa mobiruby- common mobiruby- ios

Slide 25

Slide 25 text

mobiruby-common • Will be common utilities with Android ver. • require method • Some POSIX based functions

Slide 26

Slide 26 text

MobiRuby stack iOS mruby mruby- cfunc Your code mruby- cocoa mobiruby- common mobiruby- ios

Slide 27

Slide 27 text

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        end end

Slide 28

Slide 28 text

Your code alert  =  Cocoa::MyAlertView._alloc._initWithTitle    "Hello",    :message,  "I  am  MobiRuby",    :delegate,  nil,    :cancelButtonTitle,  "I  know!",    :otherButtonTitles,  "What's?",  nil alert._setDelegate  alert alert._show

Slide 29

Slide 29 text

Road map • Finished building Cocoa bridge • Fix bugs, Improvement • Packaging • Documentation • Build wrapped APIs

Slide 30

Slide 30 text

Road map • Finished building Cocoa bridge • Fix bugs, Improvement • Packaging • Documentation • Build wrapped APIs

Slide 31

Slide 31 text

Road map • Finished building Cocoa bridge • Fix bugs, Improvement • Packaging • Documentation • Build wrapped APIs Version 1 Q1 2013

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

What’s difference? • RubyMotion • Rhodes • Ruboto • RubyCocoa • Titanium Mobile

Slide 35

Slide 35 text

What’s difference? • RubyMotion • Rhodes • Ruboto • RubyCocoa • Titanium Mobile Diversity is Good

Slide 36

Slide 36 text

Pros. • Ruby power • Based on Matz implemented Ruby • MIT license • Compact (~3000 lines) • An unexplored field

Slide 37

Slide 37 text

Cons. • Buggy • Less classes / functions • Don't have debugging feature • Need to understand iOS and Cocoa

Slide 38

Slide 38 text

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?

Slide 39

Slide 39 text

Can I use RubyGems? • No, mruby doesn’t have compatibility with CRuby ext. APIs. • You need to write new extension for mruby

Slide 40

Slide 40 text

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)

Slide 41

Slide 41 text

Can I use existing Cocoa libraries? • Yes, you can use almost all existing libraries. • I think CocoaPods will be a good partner

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

What version iOS does it support? • MobiRuby supports iOS4 and higher version. • I tested on iOS4 and iOS5. Probably run on iOS6.

Slide 44

Slide 44 text

Wanted contributions • Here’s your big chance! • Need understanding C/Objective-C and iOS development • Owned OSX and iOS developer license

Slide 45

Slide 45 text

Thank you • Logo design: Maylis Agniel • http://mobiruby.org • http://fb.me/mobiruby • http://twitter.com/mobiruby • http://github.com/mobiruby