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

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

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

23f4d5d797a91b6d17d627b90b5a42d9?s=128

Kentaro Kuribayashi

July 28, 2017
Tweet

Transcript

  1. 18.

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

    ίʔυΛ౉͢˞ mrb_valueܕ ͔Βద੾ͳܕ΁ม׵ ˞ࠓճ͸ͦ͏͍ͯ͠Δ͚ͩͰɺ࣮ࡍʹ͸ͦͷଞʹ΋ϑΝΠϧΛΘͨ͢ͱ͔͍Ζ͍Ζํ๏͕͋Γ·͢ɻ
  2. 22.

    FDIPαʔόͷίΞߏ଄ମ typedef struct em_t { int reply_count; // ϦΫΤετ΁ͷฦ৴ճ਺ char

    *reply_prefix; // ϓϩϯϓτͷจࣈྻ mrb_state *mrb; } em; Emߏ଄ମͷఆٛ
  3. 27.

    ϙΠϯτ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. 29.

    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 git@github.com:mruby/mruby.git vendor/mruby $ cd vendor/mruby && rake all NSVCZΛ΋͖ͬͯͯϏϧυ͢Δ