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を組み込む方法 / How to Embed mruby into M...
Search
Kentaro Kuribayashi
July 28, 2017
Technology
3
2.8k
ミドルウェアにmrubyを組み込む方法 / How to Embed mruby into Middlewares Written in C
真夏の技術部&BPR室 TechMTG #3(ペパボ社内勉強会)
Kentaro Kuribayashi
July 28, 2017
Tweet
Share
More Decks by Kentaro Kuribayashi
See All by Kentaro Kuribayashi
Bidirectional Quadratic Voting Leveraging Issue-Based Matching
kentaro
2
300
大高生へのメッセージ(令和6年度「大高未来塾」) / Messages to Current Students
kentaro
0
220
「始め方」の始め方 / How to Start Starting Things
kentaro
5
820
Dynamic IoT Applications and Isomorphic IoT Systems Using WebAssembly
kentaro
1
1.2k
わたしがこのところハマっている「ライセンスフリー無線」のご紹介 / An Invitation to License-Free Radio
kentaro
1
460
先行きの見えなさを楽しさに変える ーVUCA時代のキャリア論と絶対他力主義ー / How to develop your career in the VUCA era
kentaro
7
4.9k
組織の生産性を高める意思決定の構造と方法 / How to do make decision rapidly and effectively
kentaro
39
22k
キャリアを時間・空間軸で考える / Thinking about your career from both time and space viewpoints
kentaro
15
16k
WEB+DB PRESSで特集記事を書く方法 / How to Become an Author of WEB+DB PRESS
kentaro
7
1.5k
Other Decks in Technology
See All in Technology
【Pycon mini 東海 2024】Google Colaboratoryで試すVLM
kazuhitotakahashi
2
560
アジャイルチームがらしさを発揮するための目標づくり / Making the goal and enabling the team
kakehashi
3
160
『Firebase Dynamic Links終了に備える』 FlutterアプリでのAdjust導入とDeeplink最適化
techiro
0
170
BLADE: An Attempt to Automate Penetration Testing Using Autonomous AI Agents
bbrbbq
0
330
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
130
データプロダクトの定義からはじめる、データコントラクト駆動なデータ基盤
chanyou0311
3
350
OCI Security サービス 概要
oracle4engineer
PRO
0
6.5k
Mastering Quickfix
daisuzu
1
160
OCI Vault 概要
oracle4engineer
PRO
0
9.7k
Chasing the White Whale of Open Source - ROI
mrbobbytables
0
100
テストコード品質を高めるためにMutation Testingライブラリ・Strykerを実戦導入してみた話
ysknsid25
7
2.7k
100 名超が参加した日経グループ横断の競技型 AWS 学習イベント「Nikkei Group AWS GameDay」の紹介/mediajaws202411
nikkei_engineer_recruiting
1
170
Featured
See All Featured
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Typedesign – Prime Four
hannesfritz
40
2.4k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Producing Creativity
orderedlist
PRO
341
39k
Statistics for Hackers
jakevdp
796
220k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
A better future with KSS
kneath
238
17k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
For a Future-Friendly Web
brad_frost
175
9.4k
Transcript
ʙγϯϓϧͳαʔόͷ֦ுΛࡐʹઆ໌͠·͢ʙ ܀ྛ݈ଠ(.01FQBCP *OD ਅՆͷٕज़෦#13ࣨ5FDI.5(ʢࣾษڧձʣ ϛυϧΣΞʹmrubyΛΈࠐΉํ๏
(.0ϖύϘגࣜձࣾ ܀ྛ݈ଠ@kentaro औక$50 https://kentarok.org
ຊτʔΫʹΑͬͯಘΒΕΔ͜ͱ w$ͷϓϩάϥϜʹNSVCZΛΈࠐΈɺNSVCZͷεΫϦ ϓτΛ࣮ߦ͢Δํ๏͕Θ͔Γ·͢ wطଘͷϛυϧΣΞʹɺNSVCZΛΈࠐΜͰ֦ுͰ͖ ΔΑ͏ʹͳΓ·͢ wͭ·ΓɺOHY@NSVCZͷΑ͏ͳͷΛ࡞ΕΔΑ͏ʹͳ Δͱ͍͏͜ͱͰ͢Ͷʂʢݪཧతʹʣ
࣍ ֦ு͢ΔϛυϧΣΞ NSVCZΈࠐΈͷखॱ ͓ΘΓʹ
֦ு͢ΔϛυϧΣΞ
FDIPαʔόΛ֦ு͍͖ͯ͠·͢
FDIPαʔόɺΫϥΠΞϯτͷ3VCZͰͷྫ αʔό ΫϥΠΞϯτ
FDIPαʔόɺΫϥΠΞϯτΛ࣮ߦ ೖྗ͞ΕͨจࣈྻΛ ͦͷ··ฦ͚ͩ͢ͷ αʔόɻ
ͳͥFDIPαʔό͔ʁ w࣮ࡍɺ$Ͱॻ͍ͨFDIPαʔόΛ֦ு͠·͢ w͜ͷFDIPαʔόΛɺͨͱ͑OHJOYͷΑ͏ͳϛυϧΣ Ξͩͱࢥ͍ͬͯͩ͘͞ɻݪཧతʹɺಉ͡Α͏ͳΓ ํͰ֦ுͰ͖·͢ w͍͖ͳΓେ͖ͳϛυϧΣΞʹऔΓΜͰͭΒ͍˞ ͷͰɺ؆୯ͳͷΛྫʹ͡Ί͍͖ͯ·͠ΐ͏ ˞$ݴޠͱNSVCZͷࣝʹՃ͑ͯɺରͱͳΔϛυϧΣΞΛ֦ு͢ΔϊϋΔඞཁ͕͋Δ͔Βɻ
NSVCZΛΈࠐΜͩFDIPαʔό ೖྗ͞ΕͨจࣈྻΛ NSVCZͷίʔυͱ͠ ͯධՁ͠ɺ݁ՌΛฦ ͢αʔό
֦ுͨ͠FDIPαʔόͷಛ w༩͑ΒΕͨจࣈྻΛɺNSVCZͷίʔυͱͯ͠ධՁ͢Δ wNSVCZͷίʔυΛ࣮ߦͨ݁͠ՌͷܕΛผͯ͠ɺద ͳจࣈྻΛฦ͢ wFDIPαʔόͷߏମʢ(em * ܕʣͷఏڙ͢Δϝϯό ؔʹNSVCZίʔυ͔Β৮ΕΒΕΔ
NSVCZΈࠐΈͷखॱ
ΈࠐΈͷखॱ ೖྗ͞ΕͨจࣈྻΛNSVCZͷίʔυͱͯ͠ධՁ͢Δ NSVCZͷίʔυͱΈࠐΈରͷϛυϧΣΞͱͷ ؒͰɺΛదͳܕʹม͢Δ NSVCZͷίʔυத͔ΒϛυϧΣΞͷίʔυʹ৮Ε ͍ͨ߹ɺΫϥεͱϝιουΛ࡞͢Δ
MJCNSVCZΛϛυϧΣΞʹΈࠐΉ
ೖྗ͞ΕͨจࣈྻΛ NSVCZͷίʔυͱͯ͠ධՁ͢Δ
ೖྗΛNSVCZͷίʔυͱ࣮ͯ͠ߦ
͔͜͜ΒͲ͏ͬͯઌʹਐΉ͔ʁ
NSVCZͱϛυϧΣΞͷؒͰ ͷܕมΛ͢Δ
ϛυϧΣΞˠNSVCZˠϛυϧΣΞ NSVCZͷ ੈք ϛυϧΣΞͷ ੈք ϛυϧΣΞͷ ੈք (char * ܕͰ
ίʔυΛ͢˞ mrb_valueܕ ͔Βదͳܕม ˞ࠓճͦ͏͍ͯ͠Δ͚ͩͰɺ࣮ࡍʹͦͷଞʹϑΝΠϧΛΘͨ͢ͱ͔͍Ζ͍Ζํ๏͕͋Γ·͢ɻ
mruby_valueܕ͔Βͷܕม ࣮ࡍͷܕΛ ఆ͢Δ ܕ͝ͱʹ ม͍ͯ͘͠
લϖʔδͷิ wࠓճͷྫ؆୯ͳFDIPαʔόͳͷͰɺͲͷܕͰ͋ͬ ͯͯ͢(char * ܕʹม͍ͯ͠·͢ wͨͩ͠ɺݩͷܕ͕Θ͔ΔΑ͏ɺNSVCZίʔυͰͷ ܕ໊Λࣔ͢จࣈྻΛՃ͍ͯ͠·͢ɻ wҰൠతʹɺΈࠐΈରͷϛυϧΣΞ͕ظ͢Δ ܕʹม͍͖ͯ͠·͢
NSVCZίʔυͷத͔Β ϛυϧΣΞͷதʹ৮Δ
FDIPαʔόͷίΞߏମ typedef struct em_t { int reply_count; // ϦΫΤετͷฦ৴ճ char
*reply_prefix; // ϓϩϯϓτͷจࣈྻ mrb_state *mrb; } em; Emߏମͷఆٛ
NSVCZͷίʔυ͔ΒϛυϧΣΞʹ৮Δ NSVCZ͔Β Emߏମͷ ίʔυΛݺͿ Χϯτ͕ ͞Ε͍ͯΔ NSVCZ͔Β Emߏମͷ ίʔυΛݺͿ
ϓϩϯϓτͷ จࣈ͕มԽ
NSVCZʹΫϥεͱϝιουΛຒΊࠐΉ EmΫϥεΛ ࡞Δ EmΫϥεʹ ϝιουΛ࡞Δ
mrb_valueܕ ͔Βదͳܕม NSVCZˠϛυϧΣΞˠNSVCZ ϛυϧΣΞͷ ੈք NSVCZͷ ੈք NSVCZͷ ੈք mrb_valueܕ
ม ͖ͬ͞ͱٯͩͶ
ϝιουΛఆٛ͢Δ Em ߏମΛ औΓग़͢ Em ߏମͷ ϝϯόΛมߋ
ϙΠϯτmrb_stateͷudϝϯό mrb_value em_mrb_method_set_reply_prefix(mrb_state *mrb, mrb_value self); ϝιουఆٛͷγάωνϟҎԼͷ௨ΓͳͷͰɺ em->mrb->ud = self;
// udϝϯό(void *)ܕ // ……snip…… em *obj = (em *)mrb->ud; // ͳͷͰɺऔΓग़͢ͱ͖ʹΩϟετ͢Δ ͋ͱͰ͏ͨΊʹmrb->udʹEmߏମΛೖΕ͓ͯ͘
MJCNSVCZΛ ϛυϧΣΞʹΈࠐΉ
MJCNSVCZΛΈࠐΉ $ gcc src/em.c src/em_server.c \ -Iinclude -Ivendor/mruby/include \ -Lvendor/mruby/build/host/lib
-lmruby \ -o build/echo-mruby ҎԼͷΑ͏ʹϏϧυͯ͠ɺMJCNSVCZΛΈࠐΉ $ git clone
[email protected]
:mruby/mruby.git vendor/mruby $ cd vendor/mruby && rake all NSVCZΛ͖ͬͯͯϏϧυ͢Δ
ͬͱ͍͍ํ๏ˣΛࢀরͷ͜ͱ http://hb.matsumoto-r.jp/entry/2015/02/07/011237
͓ΘΓʹ
͋ͱˣΛΈͯͬͨΒ࡞ΕΔ https://github.com/kentaro/echo-mruby
͓ΘΓʹ w͍͖ͳΓ͍ͭ͝ϛυϧΣΞΛ֦ு͠Α͏ͱ͢Δͱɺ NSVCZͱؔͳ͍ͱ͜ΖͰΘ͔Βͳ͘ͳΔͷͰɺ؆୯ ͳྫͰΈࠐΈΛߦͬͯΈ·ͨ͠ w͓͍ͷϛυϧΣΞͷ֦ுੑʹࠔͬͨΒɺNSVCZΛ ΈࠐΉ͜ͱͰָ͕Ͱ͖ͳ͍͔ߟ͑ͯΈ·͠ΐ͏ w͋ͱɺ͍͍ײ͡ʹόʔϯʂͱΑΖ͘͠
NSVCZΔͷʹϖύϘΊͪΌ࠷ߴ ΤϥʔͰϋϚͬͯࢮΜͰ͚ͨͲɺ @matsumotory @udzura ͷ໊྆ʹฉ͍ͨΒ͙͢ղܾ͠ ͨ