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.4k
Other Decks in Technology
See All in Technology
誰も全体を知らない ~ ロールの垣根を超えて引き上げる開発生産性 / Boosting Development Productivity Across Roles
kakehashi
1
140
"君は見ているが観察していない"で考えるインシデントマネジメント
grimoh
4
1.1k
Amplify Gen2 Deep Dive / バックエンドの型をいかにしてフロントエンドへ伝えるか #TSKaigi #TSKaigiKansai #AWSAmplifyJP
tacck
PRO
0
210
マルチモーダル / AI Agent / LLMOps 3つの技術トレンドで理解するLLMの今後の展望
hirosatogamo
29
7.7k
利きプロセススケジューラ
sat
PRO
5
2.7k
OCI Data Integration技術情報 / ocidi_technical_jp
oracle4engineer
PRO
1
2.6k
Microsoft MVPになる前、なってから/Fukuoka_Tech_Women_Community_1_baba
nina01
0
180
Terraform Stacks入門 #HashiTalks
msato
0
320
dev 補講: プロダクトセキュリティ / Product security overview
wa6sn
0
1.8k
なぜ今 AI Agent なのか _近藤憲児
kenjikondobai
2
1.2k
ISUCONに強くなるかもしれない日々の過ごしかた/Findy ISUCON 2024-11-14
fujiwara3
8
800
Going down the RAT hole: Deep dive into the Vuln-derland of APT-class RAT Tools
nttcom
0
330
Featured
See All Featured
How STYLIGHT went responsive
nonsquared
95
5.2k
Unsuck your backbone
ammeep
668
57k
Building Your Own Lightsaber
phodgson
103
6.1k
A designer walks into a library…
pauljervisheath
202
24k
Become a Pro
speakerdeck
PRO
25
5k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
A better future with KSS
kneath
238
17k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
The Cult of Friendly URLs
andyhume
78
6k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Automating Front-end Workflow
addyosmani
1366
200k
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 ͷ໊྆ʹฉ͍ͨΒ͙͢ղܾ͠ ͨ