Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ミドルウェアにmrubyを組み込む方法 / How to Embed mruby into M...

ミドルウェアにmrubyを組み込む方法 / How to Embed mruby into Middlewares Written in C

真夏の技術部&BPR室 TechMTG #3(ペパボ社内勉強会)

Kentaro Kuribayashi

July 28, 2017
Tweet

More Decks by Kentaro Kuribayashi

Other Decks in Technology

Transcript

  1. ϛυϧ΢ΣΞˠNSVCZˠϛυϧ΢ΣΞ NSVCZͷ ੈք ϛυϧ΢ΣΞͷ ੈք ϛυϧ΢ΣΞͷ ੈք (char * ܕͰ

    ίʔυΛ౉͢˞ mrb_valueܕ ͔Βద੾ͳܕ΁ม׵ ˞ࠓճ͸ͦ͏͍ͯ͠Δ͚ͩͰɺ࣮ࡍʹ͸ͦͷଞʹ΋ϑΝΠϧΛΘͨ͢ͱ͔͍Ζ͍Ζํ๏͕͋Γ·͢ɻ
  2. FDIPαʔόͷίΞߏ଄ମ typedef struct em_t { int reply_count; // ϦΫΤετ΁ͷฦ৴ճ਺ char

    *reply_prefix; // ϓϩϯϓτͷจࣈྻ mrb_state *mrb; } em; Emߏ଄ମͷఆٛ
  3. ϙΠϯτ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ߏ଄ମΛೖΕ͓ͯ͘
  4. 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Λ΋͖ͬͯͯϏϧυ͢Δ