[Groonga-commit] groonga/groonga at f55de60 [master] mruby: Wrap member 'next' of grn_accessor in ruby method

Back to archive index

wanabe null+****@clear*****
Fri Oct 11 19:01:58 JST 2013


wanabe	2013-10-11 19:01:58 +0900 (Fri, 11 Oct 2013)

  New Revision: f55de60a2e03e6205bebbd79522240e6f1e31c89
  https://github.com/groonga/groonga/commit/f55de60a2e03e6205bebbd79522240e6f1e31c89

  Merged 8bf2bf8: Merge pull request #116 from wanabe/mruby-accessor

  Message:
    mruby: Wrap member 'next' of grn_accessor in ruby method

  Modified files:
    lib/mrb/mrb_expr.c

  Modified: lib/mrb/mrb_expr.c (+20 -2)
===================================================================
--- lib/mrb/mrb_expr.c    2013-10-10 22:09:18 +0900 (e6b6477)
+++ lib/mrb/mrb_expr.c    2013-10-11 19:01:58 +0900 (0ec386e)
@@ -182,10 +182,13 @@ scan_info_build(grn_ctx *ctx, grn_obj *expr, int *n,
                 case GRN_ACCESSOR :
                   if (grn_column_index(ctx, ec->value, c->op, &index, 1, &sid)) {
                     mrb_value mrb_ec = mrb_grn_expr_code_new(mrb, ec);
+                    mrb_value mrb_accessor_next;
                     weight = mrb_fixnum(mrb_funcall(mrb, mrb_ec, "weight", 0));
                     grn_scan_info_set_flags(si, grn_scan_info_get_flags(si) | SCAN_ACCESSOR);
                     mrb_si = mrb_grn_scan_info_new(mrb, si);
-                    if (((grn_accessor *)ec->value)->next) {
+                    mrb_accessor_next = mrb_funcall(mrb, mrb_obj_value(ctx->impl->mrb.module), "next", 1,
+                                                    mrb_cptr_value(mrb, ec->value));
+                    if (!mrb_nil_p(mrb_accessor_next)) {
                       mrb_funcall(mrb, mrb_si, "put_index", 3,
                                   mrb_cptr_value(mrb, ec->value),
                                   mrb_fixnum_value(sid),
@@ -245,7 +248,9 @@ scan_info_build(grn_ctx *ctx, grn_obj *expr, int *n,
           } else if (GRN_ACCESSORP(*p)) {
             grn_scan_info_set_flags(si, grn_scan_info_get_flags(si) | SCAN_ACCESSOR);
             if (grn_column_index(ctx, *p, c->op, &index, 1, &sid)) {
-              if (((grn_accessor *)(*p))->next) {
+              mrb_value mrb_accessor_next = mrb_funcall(mrb, mrb_obj_value(ctx->impl->mrb.module), "next", 1,
+                                                        mrb_cptr_value(mrb, *p));
+              if (!mrb_nil_p(mrb_accessor_next)) {
                 mrb_si = mrb_grn_scan_info_new(mrb, si);
                 mrb_funcall(mrb, mrb_si, "put_index", 3,
                             mrb_cptr_value(mrb, *p),
@@ -471,6 +476,18 @@ 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_accessor_next(mrb_state *mrb, mrb_value self)
+{
+  grn_accessor *accessor;
+  mrb_value mrb_accessor;
+
+  mrb_get_args(mrb, "o", &mrb_accessor);
+  accessor = mrb_cptr(mrb_accessor);
+  if (!accessor->next) { return mrb_nil_value(); }
+  return mrb_cptr_value(mrb, accessor->next);
+}
+
 void
 grn_mrb_expr_init(grn_ctx *ctx)
 {
@@ -480,6 +497,7 @@ grn_mrb_expr_init(grn_ctx *ctx)
 
   mrb_define_class_method(mrb, module,
                           "build", mrb_grn_expr_build, MRB_ARGS_REQ(4));
+  mrb_define_class_method(mrb, module, "next", mrb_grn_accessor_next, MRB_ARGS_REQ(1));
 
   klass = mrb_define_class_under(mrb, module, "ScanInfo", mrb->object_class);
   MRB_SET_INSTANCE_TT(klass, MRB_TT_DATA);
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index