Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

mruby の Hello World

jinroq
July 20, 2018
490

mruby の Hello World

2018/07/20 Fukuoka.rb #100 LT

jinroq

July 20, 2018
Tweet

Transcript

  1. •mrb_state *mrb = mrb_open();
 
 
 •mrb_load_string(mrb, “p ‘hello world!’”);


    
 
 •mrb_close(mrb);
 
 → ϙΠϯλʔม਺ mrb ΛΦʔϓϯͯͦ͠͏ → mrb ΛΫϩʔζͯͦ͠͏ → mrb ʹจࣈྻΛϩʔυͯͦ͠͏
  2. •mrb_state *mrb = mrb_open();
 
 
 •mrb_load_string(mrb, “p ‘hello world!’”);


    
 
 •mrb_close(mrb);
 
 → ϙΠϯλʔม਺ mrb ΛΦʔϓϯͯͦ͠͏ → mrb ΛΫϩʔζͯͦ͠͏ → mrb ʹจࣈྻΛϩʔυͯͦ͠͏ → mrb ͷϝϞϦʔྖҬΛ֬อͯͦ͠͏ → mrb ͷϝϞϦʔྖҬΛղ์ͯͦ͠͏
  3. •mrb_state *mrb = mrb_open();
 
 
 •mrb_load_string(mrb, “p ‘hello world!’”);


    
 
 •mrb_close(mrb);
 
 → ϙΠϯλʔม਺ mrb ΛΦʔϓϯͯͦ͠͏ → mrb ΛΫϩʔζͯͦ͠͏ → mrb ʹจࣈྻΛϩʔυͯͦ͠͏ → mrb ͷϝϞϦʔྖҬΛ֬อͯͦ͠͏ → mrb ͷϝϞϦʔྖҬΛղ์ͯͦ͠͏ → mrb ʹจࣈྻΛϩʔυ࣮ͯ͠ߦͯͦ͠͏
  4. 1. όʔνϟϧϚγϯΛද͢ʮmrb_stateʯͷॳظԽ 2. ϓϩάϥϜݻ༗ͷΫϥεɺϝιουͷఆٛ 3. Ruby ϓϩάϥϜͷίϯύΠϧͱ࣮ߦ 4. ඞཁʹԠͯ͡ʢϓϩάϥϜݻ༗ͷʣϝιουͷ ݺͼग़͠

    5. ޙ࢝຤ mruby Λ૊ΈࠐΜͩϓϩάϥϜͷڍಈ → mrb_open() → mrb_close(mrb) → mrb_load_string(mrb, “p ‘hello world!’”)
  5. gdb

  6. ᶃ Ϩδελʔ R1 ʹ self ΛϩʔυʢϨγʔόʔΛઃఆʣ ᶄ Ϩδελʔ R2 ʹ

    ‘hello world!’ Λ୅ೖʢҾ਺Λઃఆʣ ᶅ Ϩδελʔ R1 ͷΦϒδΣΫτʹରͯ͠ ‘p’ ϝιουΛ Ҿ਺͕̍ͭͰ࣮ߦ ɾɾɾᶃ ɾɾɾᶄ ɾɾɾᶅ
  7. ᶃ Ϩδελʔ R1 ʹ self ΛϩʔυʢϨγʔόʔΛઃఆʣ ᶄ Ϩδελʔ R2 ʹ

    ‘hello world!’ Λ୅ೖʢҾ਺Λઃఆʣ ᶅ Ϩδελʔ R1 ͷΦϒδΣΫτʹରͯ͠ ‘p’ ϝιουΛ Ҿ਺͕̍ͭͰ࣮ߦ ɾɾɾᶃ ɾɾɾᶄ ɾɾɾᶅ → ݁Ռ “hello world!” Λग़ྗ͢Δ
  8. ͭ·Γ mrb_load_string(mrb, “p ‘hello world!’”) ͸ 1. mruby VM Λද͢

    mrb ʹ 2. “p ‘hello world!’” ΛόΠτίʔυʹม׵ͯ͠
 ϩʔυ͠ 3. mruby ͷόΠτίʔυ໋ྩʹै࣮ͬͯߦ͢Δ ͱ͍͏΋ͷͰ͸ͳ͍͔ͱ͍͏ਪଌ
  9. ͭ·Γ mrb_load_string(mrb, “p ‘hello world!’”) ͸ 1. mruby VM Λද͢

    mrb ʹ 2. “p ‘hello world!’” ΛόΠτίʔυʹม׵ͯ͠
 ϩʔυ͠ 3. mruby ͷόΠτίʔυ໋ྩʹै࣮ͬͯߦ͢Δ ͱ͍͏΋ͷͰ͸ͳ͍͔ͱ͍͏ਪଌ → Ruby ϓϩάϥϜͷίϯύΠϧͱ࣮ߦ