Upgrade to Pro — share decks privately, control downloads, hide ads and more …

mrubyとものづくり

Yuichiro MASUI
May 18, 2013
190

 mrubyとものづくり

2013/05/18 名古屋にて

Yuichiro MASUI

May 18, 2013
Tweet

Transcript

  1. Hi! I’m @masuidrive. • Yuichiro MASUI - Ichi • Open

    source developer, Ruby fun • Pukiwiki, Ruby on Rails tutorial movie in Japanese, IKEA hacker • Furo-grammer (Coding in hot tub) • FrogApps, Inc. CTO // ex-Appcelerati Saturday, May 18, 13
  2. Hi! I’m @masuidrive. • Yuichiro MASUI - Ichi • Open

    source developer, Ruby fun • Pukiwiki, Ruby on Rails tutorial movie in Japanese, IKEA hacker • Furo-grammer (Coding in hot tub) • FrogApps, Inc. CTO // ex-Appcelerati Saturday, May 18, 13
  3. Hi! I’m @masuidrive. • Yuichiro MASUI - Ichi • Open

    source developer, Ruby fun • Pukiwiki, Ruby on Rails tutorial movie in Japanese, IKEA hacker • Furo-grammer (Coding in hot tub) • FrogApps, Inc. CTO // ex-Appcelerati Saturday, May 18, 13
  4. Hi! I’m @masuidrive. • Yuichiro MASUI - Ichi • Open

    source developer, Ruby fun • Pukiwiki, Ruby on Rails tutorial movie in Japanese, IKEA hacker • Furo-grammer (Coding in hot tub) • FrogApps, Inc. CTO // ex-Appcelerati Saturday, May 18, 13
  5. Hi! I’m @masuidrive. • Yuichiro MASUI - Ichi • Open

    source developer, Ruby fun • Pukiwiki, Ruby on Rails tutorial movie in Japanese, IKEA hacker • Furo-grammer (Coding in hot tub) • FrogApps, Inc. CTO // ex-Appcelerati ϛΠϧ Saturday, May 18, 13
  6. mruby • Ruby for less resources • ISO/JIS compliant •

    CRuby subset. Not included File, Socket, Thread and more ext libraries • OS / CPU Independent • Not required POSIX, only C99 Saturday, May 18, 13
  7. Configurable • Drop off unnecessary features • Parser / Compiler

    • Struct, Time, Math, STDIO, Regexp, sprintf • Table algorithm - hash or list • NaN Boxing Saturday, May 18, 13
  8. mruby target • Embedded • Digital Appliance • Game console

    • Vendor machine • Bundle with applications Saturday, May 18, 13
  9. mruby target • CPU - 32bit, FPU • Memory -

    256KB - 1MB • OS Saturday, May 18, 13
  10. mruby internals • VM structure - Multi VM instance •

    No C global variable • Generational incremental GC (Mark&Sweep) • Not thread safe • Build system build on CRuby Saturday, May 18, 13
  11. development • Spring 2010 - Subsidy • Matz, some companies

    and colleges • April 22, 2012 - Publish to GitHub • mruby got some contributors Saturday, May 18, 13
  12. mrbgems • Daniel (@bovi) created extension package feature at end

    of Nov 2012. • Easy to install from GitHub • Supported cross build • Already provided 40+ gems Saturday, May 18, 13
  13. mrbgems • Daniel (@bovi) created extension package feature at end

    of Nov 2012. • Easy to install from GitHub • Supported cross build • Already provided 40+ gems Saturday, May 18, 13
  14. When will you release RiteVM? I want to run it

    on iOS/ Android. It’s mruby. I need more time to make public (probably June) Should I give you access to private repos? Yes! I want to try it! What’s your github account? Saturday, May 18, 13
  15. What’s MobiRuby? • iOS app development kit on mruby •

    MIT license • Can access native functions • Have plan for Android version • Already released MobiRuby based app • Search “mobiruby” in AppStore on iOS Saturday, May 18, 13
  16. Vision • Provide Ruby power to Mobile devices • Meta

    programming is most important Ruby power Saturday, May 18, 13
  17. Hello world \ 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                        urlstr  =  "http://mobiruby.org"                        url  =  Cocoa::NSURL._URLWithString(urlstr)                        app._openURL  url                end        end end alert  =  Cocoa::MyAlertView._alloc._initWithTitle  "Hello",    :message,  "I  am  MobiRuby",    :delegate,  nil,    :cancelButtonTitle,  "I  know!",    :otherButtonTitles,  "What's?",  nil alert._setDelegate  alert alert._show Saturday, May 18, 13
  18. Hello world \ 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                        urlstr  =  "http://mobiruby.org"                        url  =  Cocoa::NSURL._URLWithString(urlstr)                        app._openURL  url                end        end end alert  =  Cocoa::MyAlertView._alloc._initWithTitle  "Hello",    :message,  "I  am  MobiRuby",    :delegate,  nil,    :cancelButtonTitle,  "I  know!",    :otherButtonTitles,  "What's?",  nil alert._setDelegate  alert alert._show Saturday, May 18, 13
  19. class  Cocoa::MyAlertView  <  Cocoa::UIAlertView    define  C::Void,  :alertView,  Cocoa::Object,  

           :clickedButtonAtIndex,  C::Int  do  |me,  idx|        if  idx.to_i  ==  1            app  =  Cocoa::UIApplication._sharedApplica            urlstr  =  "http://mobiruby.org"            url  =  Cocoa::NSURL._URLWithString(urlstr)            app._openURL  url        end    end end class  Cocoa::MyAlertView  <  Cocoa::UIAlertView    define  C::Void,  :alertView,  Cocoa::Object,          :clickedButtonAtIndex,  C::Int  do  |me,  idx|        if  idx.to_i  ==  1            app  =  Cocoa::UIApplication._sharedApplica            urlstr  =  "http://mobiruby.org"            url  =  Cocoa::NSURL._URLWithString(urlstr)            app._openURL  url        end    end end Hello world - 1st half Saturday, May 18, 13
  20. class  Cocoa::MyAlertView  <  Cocoa::UIAlertView    define  C::Void,  :alertView,  Cocoa::Object,  

           :clickedButtonAtIndex,  C::Int  do  |me,  idx|        if  idx.to_i  ==  1            app  =  Cocoa::UIApplication._sharedApplica            urlstr  =  "http://mobiruby.org"            url  =  Cocoa::NSURL._URLWithString(urlstr)            app._openURL  url        end    end end Hello world - 1st half class  Cocoa::MyAlertView  <  Cocoa::UIAlertView Saturday, May 18, 13
  21. class  Cocoa::MyAlertView  <  Cocoa::UIAlertView    define  C::Void,  :alertView,  Cocoa::Object,  

           :clickedButtonAtIndex,  C::Int  do  |me,  idx|        if  idx.to_i  ==  1            app  =  Cocoa::UIApplication._sharedApplica            urlstr  =  "http://mobiruby.org"            url  =  Cocoa::NSURL._URLWithString(urlstr)            app._openURL  url        end    end end    define  C::Void,  :alertView,  Cocoa::Object,          :clickedButtonAtIndex,  C::Int  do  |me,  idx| Hello world - 1st half Saturday, May 18, 13
  22. Hello world - 2nd half \ alert  =  Cocoa::MyAlertView._alloc.  

     _initWithTitle  "Hello",    :message,  "I  am  MobiRuby",    :delegate,  nil,    :cancelButtonTitle,  "I  know!",    :otherButtonTitles,  "What's?",  nil alert._setDelegate  alert alert._show alert  =  Cocoa::MyAlertView._alloc.    _initWithTitle  "Hello",    :message,  "I  am  MobiRuby",    :delegate,  nil,    :cancelButtonTitle,  "I  know!",    :otherButtonTitles,  "What's?",  nil alert._setDelegate  alert alert._show Saturday, May 18, 13
  23. Hello world - 2nd half \ alert  =  Cocoa::MyAlertView._alloc.  

     _initWithTitle  "Hello",    :message,  "I  am  MobiRuby",    :delegate,  nil,    :cancelButtonTitle,  "I  know!",    :otherButtonTitles,  "What's?",  nil alert._setDelegate  alert alert._show alert  =  Cocoa::MyAlertView._alloc.    _initWithTitle  "Hello",    :message,  "I  am  MobiRuby",    :delegate,  nil,    :cancelButtonTitle,  "I  know!",    :otherButtonTitles,  "What's?",  nil alert._setDelegate  alert alert._show Saturday, May 18, 13
  24. Next step \ class  MyAlertView  <  MobiRuby::AlertView    title  "Hello"

       message  "I  am  MobiRuby"    cancelButton  "I  know!"  do    end    button  "What's?"  do        openURL  "http://mobiruby.org"    end end alert  =  MyAlertView.new alert.show Saturday, May 18, 13
  25. MobiRuby stack iOS mruby mruby- cfunc Your code mruby- cocoa

    mobiruby- common mobiruby- ios Saturday, May 18, 13
  26. MobiRuby stack iOS mruby mruby- cfunc Your code mruby- cocoa

    mobiruby- common mobiruby- ios Saturday, May 18, 13
  27. MobiRuby stack iOS mruby mruby- cfunc Your code mruby- cocoa

    mobiruby- common mobiruby- ios Saturday, May 18, 13
  28. mruby-cfunc • C function bridge for mruby • Call C

    based function directly • Based on libFFI • Same as Ruby/DL library on CRuby Saturday, May 18, 13
  29. mruby-cfunc str  =  "STRING" ptr  =  CFunc::Pointer.malloc(7) result_ptr  =  CFunc::call(CFunc::Pointer,

      "strcpy",  ptr,  str) ptr.to_s -­‐>  “STRING” Saturday, May 18, 13
  30. mruby-cfunc \ class  TestStruct  <  CFunc::Struct        define

     CFunc::SInt8,    :x,                      CFunc::SInt16,  :y end test  =  TestStruct.new test[:x]  =  10 Saturday, May 18, 13
  31. MobiRuby stack iOS mruby mruby- cfunc Your code mruby- cocoa

    mobiruby- common mobiruby- ios Saturday, May 18, 13
  32. 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 Saturday, May 18, 13
  33. 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 Saturday, May 18, 13
  34. Memory management • Objective-C - Reference count • mruby -

    Mark & Sweep • Swizzled Objective-C “release” method • awful performance bottleneck Saturday, May 18, 13
  35. MobiRuby stack iOS mruby mruby- cfunc Your code mruby- cocoa

    mobiruby- common mobiruby- ios Saturday, May 18, 13
  36. mobiruby-common • Will be common utilities with Android ver. •

    require method • Some POSIX based functions Saturday, May 18, 13
  37. MobiRuby stack iOS mruby mruby- cfunc Your code mruby- cocoa

    mobiruby- common mobiruby- ios Saturday, May 18, 13
  38. Wrapped APIs \ class  MyAlertView  <  MobiRuby::AlertView    title  "Hello"

       message  "I  am  MobiRuby"    cancelButton  "I  know!"  do    end    button  "What's?"  do        openURL  "http://mobiruby.org"    end end alert  =  MyAlertView.new alert.show Saturday, May 18, 13
  39. Road map • Finished building Cocoa bridge • Fix bugs,

    Improvement • Packaging • Documentation • Build wrapped APIs Saturday, May 18, 13
  40. Road map • Finished building Cocoa bridge • Fix bugs,

    Improvement • Packaging • Documentation • Build wrapped APIs Version 1 Q1 2013 Saturday, May 18, 13
  41. Road map • Finished building Cocoa bridge • Fix bugs,

    Improvement • Packaging • Documentation • Build wrapped APIs Version 1 Summer 2013 Saturday, May 18, 13
  42. Current status • Already MobiRuby based app is in AppStore

    • Finally released alpha 1 • Can call almost iOS native functions • Writing test codes • It's only for iOS and mruby hackers Saturday, May 18, 13
  43. Pros. • Ruby power • Based on Matz implemented Ruby

    • mrbgems • MIT license • Compact (~4000 lines) Saturday, May 18, 13
  44. Cons. • Unstable • Less classes / functions • Don't

    have debugging feature • Need to understand iOS and Cocoa Saturday, May 18, 13
  45. Thank you • Logo design: Maylis Agniel • English review:

    @tenderlove and ebi-chan • http://mobiruby.org • http://github.com/mobiruby • http://twitter.com/mobiruby • http://fb.me/mobiruby Saturday, May 18, 13