[Groonga-commit] groonga/groonga at f180c03 [master] mrb: define Groonga::Object#== as equivalency check predicate

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Sep 11 23:00:52 JST 2014


Kouhei Sutou	2014-09-11 23:00:52 +0900 (Thu, 11 Sep 2014)

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

  Message:
    mrb: define Groonga::Object#== as equivalency check predicate

  Modified files:
    lib/mrb/mrb_obj.c

  Modified: lib/mrb/mrb_obj.c (+21 -0)
===================================================================
--- lib/mrb/mrb_obj.c    2014-09-10 10:22:52 +0900 (de3bf67)
+++ lib/mrb/mrb_obj.c    2014-09-11 23:00:52 +0900 (142a242)
@@ -91,6 +91,26 @@ object_grn_inspect(mrb_state *mrb, mrb_value self)
   return inspected;
 }
 
+static mrb_value
+object_equal(mrb_state *mrb, mrb_value self)
+{
+  grn_obj *object, *other_object;
+  mrb_value mrb_other;
+
+  mrb_get_args(mrb, "o", &mrb_other);
+  if (!mrb_obj_is_kind_of(mrb, mrb_other, mrb_obj_class(mrb, self))) {
+    return mrb_false_value();
+  }
+
+  object = DATA_PTR(self);
+  other_object = DATA_PTR(mrb_other);
+  if (object == other_object) {
+    return mrb_true_value();
+  } else {
+    return mrb_false_value();
+  }
+}
+
 void
 grn_mrb_obj_init(grn_ctx *ctx)
 {
@@ -108,6 +128,7 @@ grn_mrb_obj_init(grn_ctx *ctx)
                     object_find_index, MRB_ARGS_REQ(1));
   mrb_define_method(mrb, klass, "grn_inspect",
                     object_grn_inspect, MRB_ARGS_NONE());
+  mrb_define_method(mrb, klass, "==", object_equal, MRB_ARGS_REQ(1));
 
   grn_mrb_load(ctx, "index_info.rb");
 }
-------------- next part --------------
HTML����������������������������...
Download 



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