Navigation Menu

Skip to content

Commit

Permalink
mrb: improve inspect
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jun 9, 2014
1 parent 3dc3672 commit 4210316
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/mrb/mrb_obj.c
Expand Up @@ -17,9 +17,11 @@
*/

#include "../ctx_impl.h"
#include "../util.h"

#ifdef GRN_WITH_MRUBY
#include <mruby.h>
#include <mruby/string.h>
#include <mruby/class.h>
#include <mruby/data.h>

Expand Down Expand Up @@ -74,6 +76,21 @@ object_find_index(mrb_state *mrb, mrb_value self)
}
}

static mrb_value
object_grn_inspect(mrb_state *mrb, mrb_value self)
{
grn_ctx *ctx = (grn_ctx *)mrb->ud;
grn_obj buffer;
mrb_value inspected;

GRN_TEXT_INIT(&buffer, 0);
grn_inspect(ctx, &buffer, DATA_PTR(self));
inspected = mrb_str_new(mrb, GRN_TEXT_VALUE(&buffer), GRN_TEXT_LEN(&buffer));
GRN_OBJ_FIN(ctx, &buffer);

return inspected;
}

void
grn_mrb_obj_init(grn_ctx *ctx)
{
Expand All @@ -89,6 +106,8 @@ grn_mrb_obj_init(grn_ctx *ctx)
mrb_define_method(mrb, klass, "name", object_get_name, MRB_ARGS_NONE());
mrb_define_method(mrb, klass, "find_index",
object_find_index, MRB_ARGS_REQ(1));
mrb_define_method(mrb, klass, "grn_inspect",
object_grn_inspect, MRB_ARGS_NONE());

grn_mrb_load(ctx, "index_info.rb");
}
Expand Down
7 changes: 7 additions & 0 deletions lib/mrb/scripts/object.rb
@@ -0,0 +1,7 @@
module Groonga
class Object
def inspect
super[0..-2] + ": #{grn_inspect}>"
end
end
end

0 comments on commit 4210316

Please sign in to comment.