Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
mruby の Hello World
Search
jinroq
July 20, 2018
0
490
mruby の Hello World
2018/07/20 Fukuoka.rb #100 LT
jinroq
July 20, 2018
Tweet
Share
More Decks by jinroq
See All by jinroq
Fukuoka.rb 2023 年度活動報告
jinroq
0
390
TRICK 2022 に入選した話
jinroq
0
220
RubyKaigiとMicrosoftと私
jinroq
0
170
msgraph: Microsoft Graph API Client with Ruby
jinroq
0
260
Fukuoka.rb 2019活動報告・2020抱負
jinroq
0
250
福岡の方から参りました Fukuoka.rb です
jinroq
0
1.7k
Microsoft Graph API Client and OpenAPI
jinroq
0
950
Fukuoka.rb #150 LT
jinroq
0
260
5 分で分かるアイキューブドシステムズ
jinroq
0
530
Featured
See All Featured
The Cult of Friendly URLs
andyhume
78
6.1k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Six Lessons from altMBA
skipperchong
27
3.5k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Embracing the Ebb and Flow
colly
84
4.5k
GitHub's CSS Performance
jonrohan
1030
460k
Code Review Best Practice
trishagee
64
17k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.3k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
247
1.3M
Transcript
mruby ͷ Hello World 2018/07/20 Fukuoka.rb #100 LT ODA Hirohito
mruby ͱԿͧʁ
mruby ͱԿͧʁ https://github.com/mruby/mruby#what-is-mruby
mruby ͱԿͧʁ ࠐιϑτΣΞʹΘΕΔࣄΛతͱͨ͠ ܰྔͳߴڃϓϩάϥϛϯάݴޠ
Hello World
αϯϓϧίʔυ https://github.com/mruby/mruby/wiki/Hello-World#source-code
࣮ߦ݁Ռ https://github.com/mruby/mruby/wiki/Hello-World#execution
ͪΐͬͱͬͯʂ
None
ͳΜ͔ίʔυ͘ͳ͍ʁ
Ruby Ͱॻ͍ͨ Hello World C Ͱॻ͍ͨ Hello World
͜ͷίʔυԿΛ͍ͬͯΔʁ
None
puts C ͷؔ
͜ΕΒ͕ mruby ͷػೳʢͷͣʣ
͜Εͻͱ·ͣແࢹ
None
1. όʔνϟϧϚγϯΛද͢ʮmrb_stateʯͷॳظԽ 2. ϓϩάϥϜݻ༗ͷΫϥεɺϝιουͷఆٛ 3. Ruby ϓϩάϥϜͷίϯύΠϧͱ࣮ߦ 4. ඞཁʹԠͯ͡ʢϓϩάϥϜݻ༗ͷʣϝιουͷ ݺͼग़͠
5. ޙ࢝ ·ͭͱΏ͖ͻΖ ࠐ Rubyʮmrubyʯͷͯ͢ ૯ूฤ ୈ 3 ճ mruby ΛΈࠐΜͩϓϩάϥϜͷڍಈ
•mrb_state *mrb = mrb_open(); •mrb_load_string(mrb, “p ‘hello world!’”);
•mrb_close(mrb);
•mrb_state *mrb = mrb_open(); •mrb_load_string(mrb, “p ‘hello world!’”);
•mrb_close(mrb); → ϙΠϯλʔม mrb ΛΦʔϓϯͯͦ͠͏ → mrb ΛΫϩʔζͯͦ͠͏ → mrb ʹจࣈྻΛϩʔυͯͦ͠͏
•mrb_state *mrb = mrb_open(); •mrb_load_string(mrb, “p ‘hello world!’”);
•mrb_close(mrb); → ϙΠϯλʔม mrb ΛΦʔϓϯͯͦ͠͏ → mrb ΛΫϩʔζͯͦ͠͏ → mrb ʹจࣈྻΛϩʔυͯͦ͠͏ → mrb ͷϝϞϦʔྖҬΛ֬อͯͦ͠͏ → mrb ͷϝϞϦʔྖҬΛղ์ͯͦ͠͏
•mrb_state *mrb = mrb_open(); •mrb_load_string(mrb, “p ‘hello world!’”);
•mrb_close(mrb); → ϙΠϯλʔม mrb ΛΦʔϓϯͯͦ͠͏ → mrb ΛΫϩʔζͯͦ͠͏ → mrb ʹจࣈྻΛϩʔυͯͦ͠͏ → mrb ͷϝϞϦʔྖҬΛ֬อͯͦ͠͏ → mrb ͷϝϞϦʔྖҬΛղ์ͯͦ͠͏ → mrb ʹจࣈྻΛϩʔυ࣮ͯ͠ߦͯͦ͠͏
1. όʔνϟϧϚγϯΛද͢ʮmrb_stateʯͷॳظԽ 2. ϓϩάϥϜݻ༗ͷΫϥεɺϝιουͷఆٛ 3. Ruby ϓϩάϥϜͷίϯύΠϧͱ࣮ߦ 4. ඞཁʹԠͯ͡ʢϓϩάϥϜݻ༗ͷʣϝιουͷ ݺͼग़͠
5. ޙ࢝ ·ͭͱΏ͖ͻΖ ࠐ Rubyʮmrubyʯͷͯ͢ ૯ूฤ ୈ 3 ճ mruby ΛΈࠐΜͩϓϩάϥϜͷڍಈ
1. όʔνϟϧϚγϯΛද͢ʮmrb_stateʯͷॳظԽ 2. ϓϩάϥϜݻ༗ͷΫϥεɺϝιουͷఆٛ 3. Ruby ϓϩάϥϜͷίϯύΠϧͱ࣮ߦ 4. ඞཁʹԠͯ͡ʢϓϩάϥϜݻ༗ͷʣϝιουͷ ݺͼग़͠
5. ޙ࢝ mruby ΛΈࠐΜͩϓϩάϥϜͷڍಈ → mrb_open() → mrb_close(mrb) → mrb_load_string(mrb, “p ‘hello world!’”)
gdb
͜͜ʹϒϨΠΫϙΠϯτΛஔ͍ͯ εςοϓΞτ࣮ߦ͢Δ
None
None
←͜͜Ͱʮhello world!ʯΛग़ྗ
←͜͜Ͱʮhello world!ʯΛग़ྗ
mrb_load_string_cxt Λ ͍͔͚ͯΈΔ
mrb_load_string_cxt ↓ mrb_load_nstring_cxt ↓ mrb_load_exec ↓ mrb_top_run ↓ mrb_vm_run ↓
mrb_vm_exec
mrb_vm_exec 2,000 ߦͷؔ
None
mruby ͷ verbose Φϓγϣϯ
None
mrb_vm_exec ؔʹ͋Δ ΦϖϥϯυͱࣅͨΑ͏ͳͷ͕ ग़ྗ͞Ε͍ͯΔؾ͕͢Δ
ͳΜ͔ಡΊΔΑ͏ͳ ؾ͕͠ͳ͘ͳ͘ͳͬͨʂ
ᶃ Ϩδελʔ R1 ʹ self ΛϩʔυʢϨγʔόʔΛઃఆʣ ᶄ Ϩδελʔ R2 ʹ
‘hello world!’ ΛೖʢҾΛઃఆʣ ᶅ Ϩδελʔ R1 ͷΦϒδΣΫτʹରͯ͠ ‘p’ ϝιουΛ Ҿ͕̍ͭͰ࣮ߦ ɾɾɾᶃ ɾɾɾᶄ ɾɾɾᶅ
ᶃ Ϩδελʔ R1 ʹ self ΛϩʔυʢϨγʔόʔΛઃఆʣ ᶄ Ϩδελʔ R2 ʹ
‘hello world!’ ΛೖʢҾΛઃఆʣ ᶅ Ϩδελʔ R1 ͷΦϒδΣΫτʹରͯ͠ ‘p’ ϝιουΛ Ҿ͕̍ͭͰ࣮ߦ ɾɾɾᶃ ɾɾɾᶄ ɾɾɾᶅ → ݁Ռ “hello world!” Λग़ྗ͢Δ
ͭ·Γ mrb_load_string(mrb, “p ‘hello world!’”) 1. mruby VM Λද͢
mrb ʹ 2. “p ‘hello world!’” ΛόΠτίʔυʹมͯ͠ ϩʔυ͠ 3. mruby ͷόΠτίʔυ໋ྩʹै࣮ͬͯߦ͢Δ ͱ͍͏ͷͰͳ͍͔ͱ͍͏ਪଌ
ͭ·Γ mrb_load_string(mrb, “p ‘hello world!’”) 1. mruby VM Λද͢
mrb ʹ 2. “p ‘hello world!’” ΛόΠτίʔυʹมͯ͠ ϩʔυ͠ 3. mruby ͷόΠτίʔυ໋ྩʹै࣮ͬͯߦ͢Δ ͱ͍͏ͷͰͳ͍͔ͱ͍͏ਪଌ → Ruby ϓϩάϥϜͷίϯύΠϧͱ࣮ߦ
·ͱΊ • Hello World ͰϋοΫ͢ΔͱԞ͕ਂ͍ • Ruby ͷ YARV ࣅͨΑ͏ͳײ͡ʁ
͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠