Kouhei Sutou
null+****@clear*****
Thu Feb 5 18:39:58 JST 2015
Kouhei Sutou 2015-02-05 18:39:58 +0900 (Thu, 05 Feb 2015) New Revision: 095b64e3bcf9e1171b23ed97afdf605156499423 https://github.com/groonga/groonga/commit/095b64e3bcf9e1171b23ed97afdf605156499423 Message: mrb writer: support array and map Added files: lib/mrb/scripts/writer.rb Modified files: lib/mrb/mrb_writer.c lib/mrb/scripts/initialize/post.rb lib/mrb/scripts/sources.am Modified: lib/mrb/mrb_writer.c (+54 -0) =================================================================== --- lib/mrb/mrb_writer.c 2015-02-05 18:30:20 +0900 (08d1e5a) +++ lib/mrb/mrb_writer.c 2015-02-05 18:39:58 +0900 (8143fd9) @@ -59,6 +59,52 @@ writer_write(mrb_state *mrb, mrb_value self) return mrb_nil_value(); } +static mrb_value +writer_open_array(mrb_state *mrb, mrb_value self) +{ + grn_ctx *ctx = (grn_ctx *)mrb->ud; + char *name; + mrb_int n_elements; + + mrb_get_args(mrb, "zi", &name, &n_elements); + GRN_OUTPUT_ARRAY_OPEN(name, n_elements); + + return mrb_nil_value(); +} + +static mrb_value +writer_close_array(mrb_state *mrb, mrb_value self) +{ + grn_ctx *ctx = (grn_ctx *)mrb->ud; + + GRN_OUTPUT_ARRAY_CLOSE(); + + return mrb_nil_value(); +} + +static mrb_value +writer_open_map(mrb_state *mrb, mrb_value self) +{ + grn_ctx *ctx = (grn_ctx *)mrb->ud; + char *name; + mrb_int n_elements; + + mrb_get_args(mrb, "zi", &name, &n_elements); + GRN_OUTPUT_MAP_OPEN(name, n_elements); + + return mrb_nil_value(); +} + +static mrb_value +writer_close_map(mrb_state *mrb, mrb_value self) +{ + grn_ctx *ctx = (grn_ctx *)mrb->ud; + + GRN_OUTPUT_MAP_CLOSE(); + + return mrb_nil_value(); +} + void grn_mrb_writer_init(grn_ctx *ctx) { @@ -70,5 +116,13 @@ grn_mrb_writer_init(grn_ctx *ctx) klass = mrb_define_class_under(mrb, module, "Writer", mrb->object_class); mrb_define_method(mrb, klass, "write", writer_write, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, klass, "open_array", + writer_open_array, MRB_ARGS_REQ(2)); + mrb_define_method(mrb, klass, "close_array", + writer_close_array, MRB_ARGS_NONE()); + mrb_define_method(mrb, klass, "open_map", + writer_open_map, MRB_ARGS_REQ(2)); + mrb_define_method(mrb, klass, "close_map", + writer_close_map, MRB_ARGS_NONE()); } #endif Modified: lib/mrb/scripts/initialize/post.rb (+2 -0) =================================================================== --- lib/mrb/scripts/initialize/post.rb 2015-02-05 18:30:20 +0900 (94daf05) +++ lib/mrb/scripts/initialize/post.rb 2015-02-05 18:39:58 +0900 (7110437) @@ -2,6 +2,8 @@ require "error" require "context" +require "writer" + require "database" require "command" require "table_cursor" Modified: lib/mrb/scripts/sources.am (+2 -1) =================================================================== --- lib/mrb/scripts/sources.am 2015-02-05 18:30:20 +0900 (9c64b1d) +++ lib/mrb/scripts/sources.am 2015-02-05 18:39:58 +0900 (fa90c59) @@ -20,4 +20,5 @@ RUBY_SCRIPT_FILES = \ scan_info.rb \ scan_info_builder.rb \ scan_info_data.rb \ - table_cursor.rb + table_cursor.rb \ + writer.rb Added: lib/mrb/scripts/writer.rb (+15 -0) 100644 =================================================================== --- /dev/null +++ lib/mrb/scripts/writer.rb 2015-02-05 18:39:58 +0900 (a8905c0) @@ -0,0 +1,15 @@ +module Groonga + class Writer + def array(name, n_elements) + open_array(name, n_elements) + yield + close_array + end + + def map(name, n_elements) + open_map(name, n_elements) + yield + close_map + end + end +end -------------- next part -------------- HTML����������������������������... Télécharger