Debian Codegraph @

lib/mrb/mrb_type.c

raw symbols SCIP
1 /*
2 Copyright(C) 2014 Brazil
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
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 "../grn_ctx_impl.h"
20
21 #ifdef GRN_WITH_MRUBY
22 #include <mruby.h>
23 #include <mruby/class.h>
24 #include <mruby/data.h>
25
26 #include "mrb_ctx.h"
27 #include "mrb_type.h"
28
29 static struct mrb_data_type mrb_grn_type_type = {
30 "Groonga::Type",
31 NULL
32 };
33
34 static mrb_value
35 mrb_grn_type_initialize(mrb_state *mrb, mrb_value self)
36 {
37 mrb_value mrb_type_ptr;
38
39 mrb_get_args(mrb, "o", &mrb_type_ptr);
40 DATA_TYPE(self) = &mrb_grn_type_type;
41 DATA_PTR(self) = mrb_cptr(mrb_type_ptr);
42 return self;
43 }
44
45 void
46 grn_mrb_type_init(grn_ctx *ctx)
47 {
48 grn_mrb_data *data = &(ctx->impl->mrb);
49 mrb_state *mrb = data->state;
50 struct RClass *module = data->module;
51 struct RClass *object_class = data->object_class;
52 struct RClass *klass;
53
54 klass = mrb_define_class_under(mrb, module, "Type", object_class);
55 MRB_SET_INSTANCE_TT(klass, MRB_TT_DATA);
56
57 mrb_define_method(mrb, klass, "initialize",
58 mrb_grn_type_initialize, MRB_ARGS_REQ(1));
59 }
60 #endif