Kouhei Sutou
null+****@clear*****
Mon Jun 29 00:22:08 JST 2015
Kouhei Sutou 2015-06-29 00:22:08 +0900 (Mon, 29 Jun 2015) New Revision: 30d314614fbbb0fe235dfc999c33f06db2b6de22 https://github.com/groonga/groonga/commit/30d314614fbbb0fe235dfc999c33f06db2b6de22 Message: mrb: add Groonga::Array.create Modified files: lib/mrb/mrb_array.c Modified: lib/mrb/mrb_array.c (+32 -0) =================================================================== --- lib/mrb/mrb_array.c 2015-06-28 23:48:59 +0900 (f19bcfa) +++ lib/mrb/mrb_array.c 2015-06-29 00:22:08 +0900 (f90a7c6) @@ -23,6 +23,7 @@ #include <mruby/class.h> #include <mruby/data.h> +#include "mrb_ctx.h" #include "mrb_array.h" static struct mrb_data_type mrb_grn_array_type = { @@ -31,6 +32,33 @@ static struct mrb_data_type mrb_grn_array_type = { }; static mrb_value +mrb_grn_array_singleton_create(mrb_state *mrb, mrb_value klass) +{ + grn_ctx *ctx = (grn_ctx *)mrb->ud; + char *name; + mrb_int name_length; + const char *path = NULL; + mrb_value mrb_value_type; + grn_obj *value_type = NULL; + grn_obj *array; + + mrb_get_args(mrb, "so", &name, &name_length, &mrb_value_type); + if (!mrb_nil_p(mrb_value_type)) { + value_type = DATA_PTR(mrb_value_type); + } + + array = grn_table_create(ctx, + name, name_length, + path, + GRN_TABLE_NO_KEY, + NULL, + value_type); + grn_mrb_ctx_check(mrb); + + return mrb_funcall(mrb, klass, "new", 1, mrb_cptr_value(mrb, array)); +} + +static mrb_value mrb_grn_array_initialize(mrb_state *mrb, mrb_value self) { mrb_value mrb_array_ptr; @@ -54,6 +82,10 @@ grn_mrb_array_init(grn_ctx *ctx) klass = mrb_define_class_under(mrb, module, "Array", table_class); MRB_SET_INSTANCE_TT(klass, MRB_TT_DATA); + mrb_define_singleton_method(mrb, (struct RObject *)klass, "create", + mrb_grn_array_singleton_create, + MRB_ARGS_REQ(2)); + mrb_define_method(mrb, klass, "initialize", mrb_grn_array_initialize, MRB_ARGS_REQ(1)); } -------------- next part -------------- HTML����������������������������...Download