Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ctx_impl_mrb.c
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2 -*- */
2 /*
3  Copyright(C) 2013 Brazil
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License version 2.1 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include "ctx_impl_mrb.h"
20 #include "ctx_impl.h"
21 
22 #include "mrb/mrb_obj.h"
23 #include "mrb/mrb_expr.h"
24 #include "mrb/mrb_accessor.h"
25 
26 #ifdef GRN_WITH_MRUBY
27 static void
28 grn_ctx_impl_mrb_init_bindings(grn_ctx *ctx)
29 {
30  mrb_state *mrb = ctx->impl->mrb.state;
31 
32  mrb->ud = ctx;
33  ctx->impl->mrb.module = mrb_define_module(mrb, "Groonga");
34 
35  grn_mrb_obj_init(ctx);
36  grn_mrb_expr_init(ctx);
38 }
39 
40 void
42 {
43  const char *grn_mruby_enabled;
44  grn_mruby_enabled = getenv("GRN_MRUBY_ENABLED");
45  if (grn_mruby_enabled && strcmp(grn_mruby_enabled, "no") == 0) {
46  ctx->impl->mrb.state = NULL;
47  ctx->impl->mrb.module = NULL;
48  } else {
49  ctx->impl->mrb.state = mrb_open();
50  grn_ctx_impl_mrb_init_bindings(ctx);
51  }
52 }
53 
54 void
56 {
57  if (ctx->impl->mrb.state) {
58  mrb_close(ctx->impl->mrb.state);
59  ctx->impl->mrb.state = NULL;
60  }
61 }
62 #else
63 void
65 {
66 }
67 
68 void
70 {
71 }
72 #endif