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

Mruby & Me

Seb Jacobs
February 11, 2013

Mruby & Me

An introduction to mruby.
Video can be found at http://skillsmatter.com/podcast/home/mruby

Seb Jacobs

February 11, 2013
Tweet

Other Decks in Technology

Transcript

  1. Mruby & Me Seb Jacobs Monday, 11 February 13

  2. Matz’s Dream flickr/moofbong Ruby for everyone, everywhere! Monday, 11 February

    13
  3. So many rubies? JRuby, Rubinius, Topaz, ... why do we

    need another one? Monday, 11 February 13
  4. What is mruby? lightweight ISO-compliant ruby small memory footprint ruby

    for embedded systems Monday, 11 February 13
  5. mruby is the same but different • compile mruby to

    bytecode • modular library system • no regexps by default • no standard library • no require! Monday, 11 February 13
  6. Hello bytecode $ mruby -e 'puts "hello lrug";' --verbose 000

    OP_LOADSELF!R1 001 OP_STRING! R2! "hello lrug" 002 OP_SEND! R1! :puts! 1 003 OP_STOP Monday, 11 February 13
  7. C calling Ruby #include <mruby.h> #include <mruby/compile.h> int main(void) {

    mrb_state *mrb = mrb_open(); char code[] = "p 'hello world!'"; printf("Executing Ruby code from C!\n"); mrb_load_string(mrb, code); return 0; } https://github.com/mruby/mruby/wiki/Hello-World Monday, 11 February 13
  8. Use it with your favourite language! Ruby in Lua Ruby

    in PHP Ruby in Node.js! Monday, 11 February 13
  9. php-mruby $mrb = new Mruby(); $mrb->assign('$myname','sebjacobs'); $mrb->run('puts $myname'); https://github.com/chobie/php-mruby Monday,

    11 February 13
  10. Embedded Ruby! Ruby in your fridge Ruby on your TV

    Ruby on Wheels! Monday, 11 February 13
  11. Build mobile apps with Mobiruby or Jamruby Monday, 11 February

    13
  12. mod_mruby r = Apache::Request.new() Apache.rputs("redirecting request!") r.filename = "/var/www/html/redirect.html" Apache::return(Apache::OK)

    https://github.com/matsumoto-r/mod_mruby Monday, 11 February 13
  13. WebRuby https://qiezi.me/projects/webruby-tutorial/ Monday, 11 February 13

  14. MTest class Test4MTest < MTest::Unit::TestCase def test_assert_empty assert_empty([], 'array empty')

    end def test_assert_equal assert_equal('', nil.to_s) end def test_assert_includes assert_includes([1,2,3], 1) end def test_assert_instance_of assert_instance_of Class, Array end end MTest::Unit.new.run https://github.com/iij/mruby-mtest Monday, 11 February 13
  15. Get involved! Monday, 11 February 13

  16. Module#constants assert('Module#constants', '15.2.2.4.24') do ! module Test4constants ! ! Const4Test4constant

    = 24 ! end ! module Test4constants2 ! ! include Test4constants ! ! Const4Test4constant2 = 42 ! end ! Test4constants.constants == [:Const4Test4constant] ! Test4constants2.constants == [:Const4Test4constant2] end Monday, 11 February 13
  17. Module#constants mrb_value mrb_mod_constants(mrb_state *mrb, mrb_value mod) { ! mrb_value ary;

    ! ary = mrb_ary_new(mrb); ! if (obj_iv_p(mod) && mrb_obj_ptr(mod)->iv) ! { iv_foreach(mrb, mrb_obj_ptr(mod)->iv, const_i, &ary); ! } ! return ary; } Monday, 11 February 13
  18. The future? mruby-ruby Monday, 11 February 13

  19. Check out • github.com/mruby/mruby • mruby.sh • github.com/iij/mruby Monday, 11

    February 13
  20. I’m @sebjacobs any questions? Monday, 11 February 13