Kouhei Sutou
null+****@clear*****
Wed Dec 4 00:22:02 JST 2013
Kouhei Sutou 2013-12-04 00:22:02 +0900 (Wed, 04 Dec 2013) New Revision: 9b70541393250b10fd063f291b1dd16e862853f3 https://github.com/groonga/groonga/commit/9b70541393250b10fd063f291b1dd16e862853f3 Message: mrb: add grn_obj to mrb_value converter Added files: lib/mrb/mrb_converter.c lib/mrb/mrb_converter.h Modified files: lib/mrb/sources.am Added: lib/mrb/mrb_converter.c (+67 -0) 100644 =================================================================== --- /dev/null +++ lib/mrb/mrb_converter.c 2013-12-04 00:22:02 +0900 (9661fdf) @@ -0,0 +1,67 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2013 Brazil + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License version 2.1 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "../ctx_impl.h" + +#ifdef GRN_WITH_MRUBY +#include <mruby.h> +#include <mruby/class.h> +#include <mruby/data.h> + +#include "mrb_converter.h" + +struct RClass * +grn_mrb_class_from_grn_obj(mrb_state *mrb, grn_obj *object) +{ + grn_ctx *ctx = (grn_ctx *)mrb->ud; + grn_mrb_data *data; + struct RClass *klass = NULL; + + data = &(ctx->impl->mrb); + switch (object->header.type) { + case GRN_COLUMN_FIX_SIZE : + klass = mrb_class_get_under(mrb, data->module, "FixedSizeColumn"); + break; + default : + break; + } + + if (!klass) { + mrb_raisef(mrb, E_ARGUMENT_ERROR, + "can't find class for object type: %#x", object->header.type); + } + + return klass; +} + +mrb_value +grn_mrb_value_from_grn_obj(mrb_state *mrb, grn_obj *object) +{ + struct RClass *mrb_class; + mrb_value mrb_object; + + if (!object) { + return mrb_nil_value(); + } + + mrb_class = grn_mrb_class_from_grn_obj(mrb, object); + mrb_object = mrb_obj_value(mrb_obj_alloc(mrb, MRB_TT_DATA, mrb_class)); + DATA_PTR(mrb_object) = object; + return mrb_object; +} +#endif Added: lib/mrb/mrb_converter.h (+37 -0) 100644 =================================================================== --- /dev/null +++ lib/mrb/mrb_converter.h 2013-12-04 00:22:02 +0900 (27223a8) @@ -0,0 +1,37 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2013 Brazil + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License version 2.1 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef GRN_MRB_CONVERTER_H +#define GRN_MRB_CONVERTER_H + +#include "../ctx.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef GRN_WITH_MRUBY +struct RClass *grn_mrb_class_from_grn_obj(mrb_state *mrb, grn_obj *object); +mrb_value grn_mrb_value_from_grn_obj(mrb_state *mrb, grn_obj *object); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* GRN_MRB_CONVERTER_H */ Modified: lib/mrb/sources.am (+2 -0) =================================================================== --- lib/mrb/sources.am 2013-12-04 00:21:20 +0900 (1eb59db) +++ lib/mrb/sources.am 2013-12-04 00:22:02 +0900 (aed8b94) @@ -3,6 +3,8 @@ libgrnmrb_la_SOURCES = \ mrb_accessor.h \ mrb_column.c \ mrb_column.h \ + mrb_converter.c \ + mrb_converter.h \ mrb_ctx.c \ mrb_ctx.h \ mrb_expr.c \ -------------- next part -------------- HTML����������������������������...Download