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. So many rubies? JRuby, Rubinius, Topaz, ... why do we

    need another one? Monday, 11 February 13
  2. 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
  3. 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
  4. 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
  5. Use it with your favourite language! Ruby in Lua Ruby

    in PHP Ruby in Node.js! Monday, 11 February 13
  6. Embedded Ruby! Ruby in your fridge Ruby on your TV

    Ruby on Wheels! Monday, 11 February 13
  7. 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
  8. 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
  9. 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