Navigation Menu

Skip to content

Commit

Permalink
mrb: bind grn_expr
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jun 9, 2014
1 parent 62f32f4 commit 50a73c1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/mrb/mrb_converter.c
Expand Up @@ -49,6 +49,9 @@ grn_mrb_class_from_grn_obj(mrb_state *mrb, grn_obj *object)
case GRN_COLUMN_INDEX :
klass = mrb_class_get_under(mrb, data->module, "IndexColumn");
break;
case GRN_EXPR :
klass = mrb_class_get_under(mrb, data->module, "Expression");
break;
case GRN_PROC :
klass = mrb_class_get_under(mrb, data->module, "Procedure");
break;
Expand Down
22 changes: 22 additions & 0 deletions lib/mrb/mrb_expr.c
Expand Up @@ -39,6 +39,10 @@ static struct mrb_data_type mrb_grn_expr_code_type = {
"Groonga::ExpressionCode",
NULL
};
static struct mrb_data_type mrb_grn_expression_type = {
"Groonga::Expression",
NULL
};

static mrb_value
mrb_grn_scan_info_new(mrb_state *mrb, scan_info *scan_info)
Expand Down Expand Up @@ -508,11 +512,23 @@ mrb_grn_expr_code_get_weight(mrb_state *mrb, mrb_value self)
return mrb_fixnum_value(grn_expr_code_get_weight(ctx, DATA_PTR(self)));
}

static mrb_value
mrb_grn_expression_initialize(mrb_state *mrb, mrb_value self)
{
mrb_value mrb_expression_ptr;

mrb_get_args(mrb, "o", &mrb_expression_ptr);
DATA_TYPE(self) = &mrb_grn_expression_type;
DATA_PTR(self) = mrb_cptr(mrb_expression_ptr);
return self;
}

void
grn_mrb_expr_init(grn_ctx *ctx)
{
mrb_state *mrb = ctx->impl->mrb.state;
struct RClass *module = ctx->impl->mrb.module;
struct RClass *object_class = ctx->impl->mrb.object_class;
struct RClass *klass;

mrb_define_class_method(mrb, module,
Expand Down Expand Up @@ -546,6 +562,12 @@ grn_mrb_expr_init(grn_ctx *ctx)
mrb_grn_expr_code_initialize, MRB_ARGS_REQ(1));
mrb_define_method(mrb, klass, "weight",
mrb_grn_expr_code_get_weight, MRB_ARGS_NONE());

klass = mrb_define_class_under(mrb, module, "Expression", object_class);
MRB_SET_INSTANCE_TT(klass, MRB_TT_DATA);
mrb_define_method(mrb, klass, "initialize",
mrb_grn_expression_initialize, MRB_ARGS_REQ(1));

grn_mrb_load(ctx, "expression.rb");
grn_mrb_load(ctx, "scan_info.rb");
}
Expand Down
2 changes: 1 addition & 1 deletion lib/mrb/scripts/expression.rb
@@ -1,4 +1,4 @@
module Groonga
class Expression < Object
class Expression
end
end

0 comments on commit 50a73c1

Please sign in to comment.