Click here to load reader

Mrubyについて 第16回 岡山ruby, ruby on rails勉強会

  • View
    1.996

  • Download
    3

Embed Size (px)

DESCRIPTION

第16回 岡山ruby, ruby on rails勉強会でmrubyについて調べたこと、試したことを発表しました。

Text of Mrubyについて 第16回 岡山ruby, ruby on rails勉強会

  • 1. mruby 16 Ruby, Ruby on Rails
  • 2. Twitter: @ore_public Github: https://github.com/ore-public Ruby 12
  • 3. OS
  • 4. JRuby https://github.com/ore-public/tetris
  • 5. 10 https://twitter.com/gunjisatoshi/status/489194078139990016
  • 6. mruby mrbgem CRuby mrbgem mrbgemmruby
  • 7. mruby ruby JRubyRubiniusRuby mruby
  • 8. $ git clone [email protected]:mruby/mruby.git $ cd mruby $ ruby ./minirake ( rake ) 4 ./bin/mrubymruby ./bin/mirb CRuby irb ./bin/mrbc (ruby ) ./bin/mruby-strip Todo
  • 9. mrbgem mrubymrbgem mrubygem CRubygem (build_config.rb) MRuby::Build.new do |conf| if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR'] toolchain :visualcpp else toolchain :gcc end enable_debug conf.gem :git => 'https://github.com/ore-public/mruby-fizzbuzz' conf.gem ../fizzbuzz conf.gembox 'default' end
  • 10. mrbgem #git conf.gem :git => 'https://github.com/ore-public/mruby-fizzbuzz' # conf.gem ../fizzbuzz #gembox conf.gembox 'default'#
  • 11. mrbgems gembox mrbgems .gembox mrbgem
  • 12. mrbgems MRuby::GemBox.new do |conf| # Use standard Kernel#sprintf method conf.gem :core => "mruby-sprintf" # Use standard print/puts/p conf.gem :core => "mruby-print" # Use standard Math module conf.gem :core => "mruby-math" default.gembox()
  • 13. mrbgems mrbgems mruby mirb gembox default mrbc
  • 14. CRuby CRuby (rbenvruby2.1.2) ruby 2,413,276 mruby mruby 705,956 1/3 Mac OS X 10.9.4
  • 15. CRuby mrbgems
  • 16. CRuby array.c (Array) CRuby (ruby2.1.2) 5700 mruby 1100
  • 17. CRuby Array CRuby > Array.instance_methods(false).size => 90 mruby > Array.instance_methods(false).size => 42
  • 18. CRuby mruby-array-ext gem > Array.instance_methods(false).size => 67
  • 19. mrbgems Arrayfizzbuzz gem mrubyC https://github.com/ore-public/mruby-fizzbuzz
  • 20. mrbgems mruby-mrbgem-template http://blog.matsumoto-r.jp/?p=3923
  • 21. mrbgems mruby-fizzbuzz LICENSE README.md mrbgem.rake mrblib mrb_fizzbuzz.rbRuby mruby-fizzbuzz.gem src mrb_fizzbuzz.cC mrb_fizzbuzz.h test mrb_fizzbuzz.rb
  • 22. mrbgems
  • 23. mrbgems mrubyC mruby mruby C
  • 24. mruby(mruby-fizzbuzz) void mrb_mruby_fizzbuzz_gem_init(mrb_state *mrb) { struct RClass *a = mrb->array_class; mrb_define_method(mrb, a, "fizzbuzz", mrb_fizzbuzz, MRB_ARGS_REQ(1)); } mrb_state mrubymrubyObject Class Module ArrayString mruby
  • 25. mruby(mruby-fizzbuzz) include/mruby.h (mrb_state) typedef struct mrb_state { struct mrb_jmpbuf *jmp; mrb_allocf allocf; /* memory allocation function */ struct mrb_context *c; struct mrb_context *root_c; struct RObject *exc; /* exception */ struct iv_tbl *globals; /* global variable table */ struct RObject *top_self; struct RClass *object_class; /* Object class */ struct RClass *class_class; struct RClass *module_class; struct RClass *proc_class; struct RClass *string_class; struct RClass *array_class; struct RClass *hash_class;
  • 26. mruby(mruby-fizzbuzz) void mrb_mruby_fizzbuzz_gem_init(mrb_state *mrb) { struct RClass *a = mrb->array_class; mrb_define_method(mrb, a, "fizzbuzz", mrb_fizzbuzz, MRB_ARGS_REQ(1)); } mrb_define_method mrb_stateArrayfizzbuzz mrb_fizzbuzzC ruby [ def ]
  • 27. mruby(mruby-fizzbuzz) static mrb_value mrb_fizzbuzz(mrb_state *mrb, mrb_value self) { mrb_int i; mrb_value v, value, fizzbuzz; value = mrb_ary_new_capa(mrb, RARRAY_LEN(self)); for (i = 0; i < RARRAY_LEN(self); ++i) { v = RARRAY_PTR(self)[i]; if((mrb_fixnum(v) % 15) == 0){ fizzbuzz = mrb_str_new_cstr(mrb, "FizzBuzz"); } else if((v.value.i % 5) == 0) { } else { fizzbuzz = v; } mrb_ary_set(mrb, value, i, fizzbuzz); } return value; } self mrb_value mruby mrb_ary_new_capa Array RARRAY_LEN Array RARRAY_PTR Array mrb_ary_set Array Array 1 fizzbuzzArray selfArray selfv
  • 28. mruby(mruby-fizzbuzz) typedef struct mrb_value { union { mrb_float f; void *p; mrb_int i; mrb_sym sym; } value; enum mrb_vtype tt; } mrb_value; mrb_value float, int, value void *p mrb_vtype voidRARRAY_PTR fizzbuzzv.value.i
  • 29. mruby mrubymrbgems CRubyArray mrbgemArray#fizzbuzz mruby
  • 30. mrbgem mrubyAPI mruby
  • 31. RHG (Ruby http://i.loveruby.net/ja/rhg/book/ mruby2013 http://qiita.com/advent-calendar/2013/mruby Code Reading Wiki http://www.dzeta.jp/~junjis/code_reading/index.php?FrontPage

Search related