Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
mruby introduction -- jinbocho.rb #01
Search
Akira Yumiyama
April 19, 2013
Programming
9
1.1k
mruby introduction -- jinbocho.rb #01
Akira Yumiyama
April 19, 2013
Tweet
Share
More Decks by Akira Yumiyama
See All by Akira Yumiyama
GAE/Python2 to Python3 Migration Journey
akiray03
0
1.5k
オブジェクト指向で考える アプリケーションアーキテクチャ設計 / Object-Oriented Conference 2020
akiray03
6
19k
Terraform Introduction
akiray03
0
79
Case Study of Machine Learning in CrowdWorks
akiray03
0
1.9k
CrowdWorksを支える管理画面 - 管理画面チラ見せ♡ナイト #5
akiray03
0
1.5k
DevSumi2015 19-D-2 IIJ社内におけるアジャイル開発、DevOpsへの取り組み
akiray03
0
400
Other Decks in Programming
See All in Programming
JaSST 24 九州:ワークショップ(は除く)実践!マインドマップを活用したソフトウェアテスト+活用事例
satohiroyuki
0
260
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
330
GCCのプラグインを作る / I Made a GCC Plugin
shouth
1
150
Golang と Erlang
taiyow
8
1.9k
Go言語でターミナルフレンドリーなAIコマンド、afaを作った/fukuokago20_afa
monochromegane
2
140
PLoP 2024: The evolution of the microservice architecture pattern language
cer
PRO
0
1.5k
Jakarta Concurrencyによる並行処理プログラミングの始め方 (JJUG CCC 2024 Fall)
tnagao7
1
230
AWS IaCの注目アップデート 2024年10月版
konokenj
3
3k
Vitest Browser Mode への期待 / Vitest Browser Mode
odanado
PRO
2
1.7k
Pinia Colada が実現するスマートな非同期処理
naokihaba
2
150
Sidekiqで実現する 長時間非同期処理の中断と再開 / Pausing and Resuming Long-Running Asynchronous Jobs with Sidekiq
hypermkt
6
2.6k
OpenTelemetryでRailsのパフォーマンス分析を始めてみよう(KoR2024)
ymtdzzz
4
1.5k
Featured
See All Featured
Designing Dashboards & Data Visualisations in Web Apps
destraynor
228
52k
Measuring & Analyzing Core Web Vitals
bluesmoon
1
39
GraphQLの誤解/rethinking-graphql
sonatard
66
9.9k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
Building Your Own Lightsaber
phodgson
102
6k
A Modern Web Designer's Workflow
chriscoyier
692
190k
Agile that works and the tools we love
rasmusluckow
327
21k
A better future with KSS
kneath
238
17k
How GitHub (no longer) Works
holman
311
140k
Speed Design
sergeychernyshev
24
570
The Art of Programming - Codeland 2020
erikaheidi
51
13k
Transcript
mruby introduction mruby unofficial logo by https://github.com/h2so5/mruby-logo @akiray03 jinbocho.rb #01
ࣗݾհ @akiray03 ࠷ۙ࡞ͬͨͷ: mruby-mtest: MiniTestϥΠΫͳςετϑϨʔ ϜϫʔΫ mruby-WiringPi: Raspberry PiͷGPIOΛૢ࡞ MRuby
Reporter: mrubyͷϏϧυ݁ՌΛू http://m.ruby.iijgio.com/ 2
Question? Rubyistͳํ? ΈࠐΈܥͳํ? CݴޠόϦόϦॻ͍ͯΔํ? 3
agenda mrubyͷհ mrubyͰHello, world mrubyͷ֦ுϞδϡʔϧΛॻ͍ͯΈΑ͏ 4
Hello, mruby git clone https://github.com/mruby/mruby.git cd mruby ruby minirake all
test ./bin/mruby -e “Hello, mruby!” 5
mrubyͱ Embeddable Minimal Implementation Considerable active committers have "M" as
their name initials, somehow. Some major committers have Matsumoto as their family name, somehow. (They are not relatives) Matz. 6 What means “m”?
ܰྔRuby? ʮܰྔRubyʯϓϩδΣΫτ໊ ϓϩδΣΫτͷՌ(ιϑτΣΞ)͕ mruby ܦ࢈লͷʮҬΠϊϕʔγϣϯग़ݚڀ։ൃࣄۀʯʹ࠾͞Εͨ(2010ʙ2012) ܰྔRubyʰΈࠐΈʱΛ೦಄ʹ։ൃ͞Ε͍ͯΔ 7
ΈࠐΈ? 8
mruby target ػثΈࠐΈ UI, Network, (ιϑτϦΞϧλΠϜͳ)੍ޚͳͲ ΞϓϦέʔγϣϯΈࠐΈ ίϯϑΟάهड़ݴޠ, ػೳ֦ு༻, Sandbox,
... 9
mrubyࡌϧʔλ! ϧʔλͷίϯϑΟάཧγεςϜͷಈ࡞ʹ mrubyΛ࠾༻ த NetBSD ϧʔλͷ౷Ұ͞ΕͨίϯϑΟάΛ ֤Daemon༻ͷίϯϑΟάʹ ม͢Δ෦ͰmrubyΛ ར༻͍ͯ͠Δ 10
ੈքॳ!
ApacheͷΈࠐΈ mod_mruby Λ͏͜ͱͰɺ Apache෦ͷঢ়ଶ Λ؆୯ʹࢹɾૢ࡞Ͱ͖Δ 11 http://blog.matsumoto-r.jp/?p=3376
mrubyͷ༦ – http://www.slideshare.net/IIJ_MOGOK/mruby-17436495
mrubyͷಛ OS / CPUґଘ͕ແ͍ (গͳ͍) CRubyͷιʔείʔυಡΉͱifdefͩΒ͚... ػೳCRubyͷαϒηοτ File, IO, Socket,
Thread, ... ؚ·Εͳ͍ จ๏CRubyͷϑϧηοτ (༧ఆ) ISO / JIS ४ڌ (༧ఆ) 13
configurable ෆཁͳػೳͦ͗མͱͤΔ Parser / Compiler p/puts/print, sprintf, Time, Math, Regexp,
... ز͔ͭͷػೳࠩ͠ସ͕͑Ͱ͖Δ Regexp: pcre, onigruma, HenrySpencer, etc... 14
mrbgems CRubyͷrubygemsͱࣅͨΈ CRubyϥϯλΠϜ࣌ʹrequire͢Δ mrubyϏϧυ࣌ʹࠐΉ͕ҟͳΔ mrubyʹ (ඪ४Ͱ) requireແ͍ͷͰ.. ΫϩεϏϧυʹରԠ طʹ60Λ͑Δgem͕ϦϦʔε͞Ε͍ͯΔ 15
mgem list mruby-msagent mruby- capability mruby-WiringPi mruby-girffi mruby-md5 mruby-discount mruby-cocoa
mruby-curl mruby-zabbix mruby-simple- random mruby-core-ext mruby-syslog mruby-process mruby-onig- regexp mruby-string- enhancement mruby-sinatic mruby-allegro mruby-sha1 mruby-sqlite3 mruby- javascriptcore mruby-dir mruby-fltk3 mruby-pack mruby-winapp mruby- httprequest mruby-oauth mruby- growthforecast mruby-audite mruby-cgroup mruby-thread mruby-libqrng mruby-jpeg mruby-random mruby-pcre- regexp mruby-mecab mruby-uv mruby-eject mruby-mysql mruby-hs-regexp mruby-redis mruby-http mruby-mtest mruby- updategems mruby-cfunc mruby-arduino mruby-require mruby-sleep mruby- simplehttp mruby-json mruby-base64 mruby-digest mruby-v8 mruby-env mruby-aws-s3 mruby-allocate mruby-gles mruby- markdown mruby-gntp mruby-dll mruby-iconv 16
iij mrbgems mruby-mtest mruby-dir mruby-digest mruby-process mruby-pack mruby-syslog mruby-env mruby-simple-
random mruby-errno mruby-aws-s3 mruby-io mruby-regexp-pcre mruby-tempfile mruby-require mruby-mdebug mruby-ipaddr Comming Soon 17
small is beautiful 18 ΤίγεςϜ(mrbgem)͕ग़དྷͨ͜ͱͰɺࣗͷ ཉ͍͠ػೳ͚͕ͩೖͬͨʮΧελϜmrubyʯ͕؆ ୯ʹखʹೖΔΑ͏ʹͳͬͨ
Hello, mruby! git clone https://github.com/mruby/mruby.git cd mruby ruby minirake all
test ./bin/mruby -e “Hello, mruby!” 19
build_config.rb .3VCZ#VJMEOFXEPcDPOGc UPPMDIBJOHDD DPOGHFN\SPPU^NSCHFNTNSVCZTQSJOUG DPOGHFN\SPPU^NSCHFNTNSVCZQSJOU DPOGHFN\SPPU^NSCHFNTNSVCZNBUI DPOGHFN\SPPU^NSCHFNTNSVCZUJNF DPOGHFN\SPPU^NSCHFNTNSVCZTUSVDU DPOGHFN\SPPU^NSCHFNTNSVCZFOVNFYU DPOGHFN\SPPU^NSCHFNTNSVCZTUSJOHFYU
DPOGHFN\SPPU^NSCHFNTNSVCZOVNFSJDFYU DPOGHFN\SPPU^NSCHFNTNSVCZBSSBZFYU DPOGHFN\SPPU^NSCHFNTNSVCZIBTIFYU DPOGHFN\SPPU^NSCHFNTNSVCZSBOHFFYU DPOGHFN\SPPU^NSCHFNTNSVCZQSPDFYU DPOGHFN\SPPU^NSCHFNTNSVCZSBOEPN DPOGHFN\SPPU^NSCHFNTNSVCZCJONJSC DPOGHFN\SPPU^NSCHFNTNSVCZCJONSVCZ FOE 20 ຊՈNSVCZͰఏڙ͢Δ NSCHFN͚ͩͰݸ
build_config.rb .3VCZ#VJMEOFXEPcDPOGc UPPMDIBJOHDD DPOGHFN\SPPU^NSCHFNTNSVCZTQSJOUG DPOGHFN\SPPU^NSCHFNTNSVCZQSJOU DPOGHFN\SPPU^NSCHFNTNSVCZNBUI DPOGHFN\SPPU^NSCHFNTNSVCZUJNF DPOGHFN\SPPU^NSCHFNTNSVCZTUSVDU DPOGHFN\SPPU^NSCHFNTNSVCZFOVNFYU DPOGHFN\SPPU^NSCHFNTNSVCZTUSJOHFYU
DPOGHFN\SPPU^NSCHFNTNSVCZOVNFSJDFYU DPOGHFN\SPPU^NSCHFNTNSVCZBSSBZFYU DPOGHFN\SPPU^NSCHFNTNSVCZIBTIFYU DPOGHFN\SPPU^NSCHFNTNSVCZSBOHFFYU DPOGHFN\SPPU^NSCHFNTNSVCZQSPDFYU DPOGHFN\SPPU^NSCHFNTNSVCZSBOEPN DPOGHFN\SPPU^NSCHFNTNSVCZCJONJSC DPOGHFN\SPPU^NSCHFNTNSVCZCJONSVCZ FOE 21 toolchain :gcc conf.gem “#{root}/mrbgems/mruby-time” ଞʹWTͳͲ
Customize mruby ./bin/mruby -e ‘p Time.now’ build_config.rb ͷ mruby-time ͷߦΛίϝϯτΞτ
ruby minirake clean all test ͏Ұ ./bin/mruby -e ‘p Time.now’ 22
Make mrbgem rand / srand Λ࡞ͬͯΈ·͠ΐ͏ mrbgems/mruby-random ϝϧηϯψπΠε λͰ͕͢ɺ؆୯ʹCͷrandͱsrandΛWrapping͢ ΔํͰ࡞ͬͯΈ·͢
αϯϓϧίʔυ github: jinbochorb/mruby mruby-rand ϒϥϯνʹ͋Γ·͢ :p 23
Make mrbgem – 1 cd $(MRUBY_DIR) mkdir mruby-rand mkdir mruby-rand/src
mkdir mruby-rand/test 24
Make mrbgem – 2 25 MRuby::Gem::Specification.new('mruby-‐rand') do |spec| spec.license
= 'MIT' spec.authors = 'mruby developers' end vi mruby-rand/mrbgem.rake
Make mrbgem – 3 26 #include “mruby.h” void mrb_mruby_rand_gem_init(mrb_state *mrb)
{ } void mrb_mruby_rand_gem_final(mrb_state *mrb) { } vi mruby-rand/src/rand.c
Make mrbgem – 3 27 #include “mruby.h” void mrb_mruby_rand_gem_init(mrb_state *mrb)
{ } void mrb_mruby_rand_gem_final(mrb_state *mrb) { } vi mruby-rand/src/rand.c gemͷ໊લΛ gsub(‘-’, ‘_’)ͨ͠ͷ
Make mrbgem – 4 28 MRuby::Build.new do |conf| #
... # mruby-‐random ΛίϝϯτΞτ͢Δ # conf.gem “#{root}/mrbgems/mruby-‐random” # mruby-‐rand Λ͢ conf.gem “#{root}/mruby-‐rand” end vi build_config.rb
Make mrbgem – 5 cd $(MRUBY_DIR) ruby minirake clean ruby
minirake all (ͱΓ͋͑ͣϏϧυ͕௨Δ͜ͱ͚ͩ֬ೝ) 29
Make mrbgem – 6 30 assert “rand is a Fixnum”
do rand.class == Fixnum end assert “rand is a positive value” do rand >= 0 end vi mruby-rand/test/rand.rb
Make mrbgem – 7 cd $(MRUBY_DIR) ruby minirake all test
(ࠓςετʹࣦഊ͍ͯ͠Δͱ͜Ζ·Ͱ֬ೝ) 31
Make mrbgem – 8 32 #include <stdlib.h> mrb_value mrb_f_rand(mrb_state *mrb,
mrb_value self) { return mrb_fixnum_value(rand()); } void mrb_mruby_rand_gem_init(mrb_state *mrb) { struct RClass *krn = mrb-‐>kernel_module; mrb_define_method(mrb, krn, “rand”, mrb_f_rand, ARGS_ANY()); } vi mruby-rand/src/rand.c
Make mrbgem – 9 cd $(MRUBY_DIR) ruby minirake all ./bin/mruby
-e ‘p rand’ ./bin/mruby -e ‘p rand, rand, rand’ 33
Make mrbgem – 10 34 #include <stdlib.h> #include <time.h>
// ←͜ͷߦΛ͢ void mrb_mruby_rand_gem_init(mrb_state *mrb) { // (snip)... srand((unsigned) time(NULL)); // ←͜ͷߦΛ͢ } vi mruby-rand/src/rand.c
Make mrbgem 35 RubyͷrandɺCͷrandͱҧ͏ͱ͜Ζ͕͋Δ Ҿແ: [0,1) ͷൣғͰFloatͷཚΛฦ͢ Ҿ༗: [0,max) ͷൣғͰFixnumͷཚΛฦ͢
Ұsrand͕ݺΕͯͳ͚ΕsrandΛݺͼग़͢ etc.. Λߟྀͯ͠࡞Δඞཁ͕͋Γ·͢ https://github.com/iij/mruby-simple-random/
·ͱΊ mruby configurable ͳ “͍ܰ” Ruby࣮ 2012य़ʹGithubͰެ։͞Εͨ mrbgemͳͲศརͳΈग़དྷͨ ػೳ֦ு(mrbgem)60
“·ͩ҆ఆ͠ͳ͍͠”... Θͳ͍ͱ҆ఆ͠·ͤΜʂ օͰͬͯ҆ఆͤ͞·͠ΐ͏ʂ 36
FAQ
FAQ Q. mrubyArduinoͰಈ͖·͔͢? Arduino DueͰಈ͍ͨͱ͍͏ใࠂ͕͋Γ·͢ http://blog.mruby.sh/201303161453.html mruby16bitڥΛਖ਼ࣜαϙʔτ͍ͯ͠·ͤΜ ArduinoͰ༻͞ΕΔAVR16bitϚΠίϯͰ͢ ArduinoϐϯޓͷchipKIT Max32,
Enzi, GR- SAKURA, Λར༻ͨ͠΄͏͕ݱ࣮తͰ͠ΐ͏ 38
FAQ Q. mrubyͷ҆ఆ൛ϦϦʔε͍ͭͰ͔͢? A. ͍ͭͳΜͰ͠ΐ͏.... ( ҆ఆ൛NPOʹͤΔ (ҙ༁) github͜ͷ··ಥ͖ਐΉ (ҙ༁)
... ͱ Matz ڼͬͯ·ͨ͠ 39
FAQ Q. mrubyͰ XXX(͓͖ͳΫϥε໊ΛೖΕͯͩ͘͞ ͍) ͑·͔͢? A. Object.const_defined?(:XXX)ͯ͠Έ͍ͯͩ͘͞ ແ͚Ε࡞ͬͯ mrbgem
ͱͯ͠ެ։͢Δͱɺ͍Ζ ͍Ζͳਓ͕تͿͱࢥ͍·͢ ཉ͍͠ͱᄁ͍ͨΒɺMͷ͘ਓ͕αΫοͱ࡞ͬͯ͘ ΕΔ͔͠Ε·ͤΜ :P 40
FAQ Q. ͳΜͰmrubyΛͬͨͷ? CRubyΛΘͳ͔ͬ ͨཧ༝? A. CRubyόΠφϦαΠζ/࣮ߦ࣌αΠζͱʹେ ͖͔ͬͨ CRubyඪ४ϥΠϒϥϦɾϑϧηοτ͕લఏ Ұ෦ͷΈऔΓ֎͢ͷ͕͍͠/໘
41