Kouhei Sutou
null+****@clear*****
Thu Oct 3 18:26:00 JST 2013
Kouhei Sutou 2013-10-03 18:26:00 +0900 (Thu, 03 Oct 2013) New Revision: 7de76f1760824fc106c0a4d8e49b7b527f76b660 https://github.com/groonga/groonga/commit/7de76f1760824fc106c0a4d8e49b7b527f76b660 Message: Start to create mruby bindings Added files: lib/mrb/Makefile.am lib/mrb/mrb_obj.h lib/mrb/sources.am test/command/suite/ruby/eval/built_in_class.expected test/command/suite/ruby/eval/built_in_class.test Copied files: lib/mrb/mrb_obj.c (from lib/ctx_impl_mrb.c) Modified files: configure.ac lib/CMakeLists.txt lib/Makefile.am lib/ctx_impl_mrb.c Modified: configure.ac (+1 -0) =================================================================== --- configure.ac 2013-10-03 18:04:10 +0900 (7ea73ba) +++ configure.ac 2013-10-03 18:26:00 +0900 (be9c1d8) @@ -220,6 +220,7 @@ AC_CONFIG_FILES([ src/httpd/Makefile lib/Makefile lib/dat/Makefile + lib/mrb/Makefile include/Makefile include/groonga/Makefile plugins/Makefile Modified: lib/CMakeLists.txt (+5 -1) =================================================================== --- lib/CMakeLists.txt 2013-10-03 18:04:10 +0900 (e580737) +++ lib/CMakeLists.txt 2013-10-03 18:26:00 +0900 (f55345b) @@ -25,8 +25,11 @@ read_file_list(${CMAKE_CURRENT_SOURCE_DIR}/sources.am LIBGROONGA_SOURCES) read_file_list(${CMAKE_CURRENT_SOURCE_DIR}/dat/sources.am LIBGRNDAT_SOURCES) string(REGEX REPLACE "([^;]+)" "dat/\\1" LIBGRNDAT_SOURCES "${LIBGRNDAT_SOURCES}") +read_file_list(${CMAKE_CURRENT_SOURCE_DIR}/mrb/sources.am LIBGRNMRB_SOURCES) +string(REGEX REPLACE "([^;]+)" "mrn/\\1" + LIBGRNMRB_SOURCES "${LIBGRNMRB_SOURCES}") -set_source_files_properties(${LIBGROONGA_SOURCES} +set_source_files_properties(${LIBGROONGA_SOURCES} ${LIBGRNMRB_SOURCES} PROPERTIES COMPILE_FLAGS "${GRN_C_COMPILE_FLAGS}") set_source_files_properties(dat.cpp ${LIBGRNDAT_SOURCES} @@ -36,6 +39,7 @@ set_source_files_properties(dat.cpp ${LIBGRNDAT_SOURCES} add_library(libgroonga SHARED ${LIBGROONGA_SOURCES} ${LIBGRNDAT_SOURCES} + ${LIBGRNMRB_SOURCES} ${MRUBY_LIBS}) set_target_properties(libgroonga PROPERTIES OUTPUT_NAME "groonga") target_link_libraries(libgroonga Modified: lib/Makefile.am (+4 -1) =================================================================== --- lib/Makefile.am 2013-10-03 18:04:10 +0900 (8ce864a) +++ lib/Makefile.am 2013-10-03 18:26:00 +0900 (b18a299) @@ -1,4 +1,6 @@ -SUBDIRS = dat +SUBDIRS = \ + dat \ + mrb lib_LTLIBRARIES = libgroonga.la @@ -21,6 +23,7 @@ libgroonga_la_LDFLAGS = \ libgroonga_la_LIBADD = \ dat/libgrndat.la \ + mrb/libgrnmrb.la \ $(MESSAGE_PACK_LIBS) \ $(MRUBY_LIBS) Modified: lib/ctx_impl_mrb.c (+4 -0) =================================================================== --- lib/ctx_impl_mrb.c 2013-10-03 18:04:10 +0900 (59f4028) +++ lib/ctx_impl_mrb.c 2013-10-03 18:26:00 +0900 (55261af) @@ -19,6 +19,8 @@ #include "ctx_impl_mrb.h" #include "ctx_impl.h" +#include "mrb/mrb_obj.h" + #ifdef GRN_WITH_MRUBY static void grn_ctx_impl_mrb_init_bindings(grn_ctx *ctx) @@ -26,6 +28,8 @@ grn_ctx_impl_mrb_init_bindings(grn_ctx *ctx) mrb_state *mrb = ctx->impl->mrb.state; ctx->impl->mrb.module = mrb_define_module(mrb, "Groonga"); + + grn_mrb_obj_init(ctx); } void Added: lib/mrb/Makefile.am (+16 -0) 100644 =================================================================== --- /dev/null +++ lib/mrb/Makefile.am 2013-10-03 18:26:00 +0900 (c1666a9) @@ -0,0 +1,16 @@ +AM_CPPFLAGS = \ + -I$(top_builddir) \ + -I$(top_srcdir)/include \ + -I$(top_srcdir)/lib + +AM_CFLAGS = \ + $(NO_STRICT_ALIASING_CFLAGS) \ + $(COVERAGE_CFLAGS) \ + $(GRN_CFLAGS) \ + $(MRUBY_CFLAGS) + +noinst_LTLIBRARIES = libgrnmrb.la + +include sources.am + +CLEANFILES = *.gcno *.gcda Copied: lib/mrb/mrb_obj.c (+10 -36) 51% =================================================================== --- lib/ctx_impl_mrb.c 2013-10-03 18:04:10 +0900 (59f4028) +++ lib/mrb/mrb_obj.c 2013-10-03 18:26:00 +0900 (ceae4b9) @@ -16,48 +16,22 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "ctx_impl_mrb.h" -#include "ctx_impl.h" +#include "../ctx_impl.h" #ifdef GRN_WITH_MRUBY -static void -grn_ctx_impl_mrb_init_bindings(grn_ctx *ctx) -{ - mrb_state *mrb = ctx->impl->mrb.state; - - ctx->impl->mrb.module = mrb_define_module(mrb, "Groonga"); -} +#include <mruby.h> +#include <mruby/class.h> -void -grn_ctx_impl_mrb_init(grn_ctx *ctx) -{ - const char *grn_mruby_enabled; - grn_mruby_enabled = getenv("GRN_MRUBY_ENABLED"); - if (grn_mruby_enabled && strcmp(grn_mruby_enabled, "no") == 0) { - ctx->impl->mrb.state = NULL; - ctx->impl->mrb.module = NULL; - } else { - ctx->impl->mrb.state = mrb_open(); - grn_ctx_impl_mrb_init_bindings(ctx); - } -} +#include "mrb_obj.h" void -grn_ctx_impl_mrb_fin(grn_ctx *ctx) +grn_mrb_obj_init(grn_ctx *ctx) { - if (ctx->impl->mrb.state) { - mrb_close(ctx->impl->mrb.state); - ctx->impl->mrb.state = NULL; - } -} -#else -void -grn_ctx_impl_mrb_init(grn_ctx *ctx) -{ -} + mrb_state *mrb = ctx->impl->mrb.state; + struct RClass *module = ctx->impl->mrb.module; + struct RClass *klass; -void -grn_ctx_impl_mrb_fin(grn_ctx *ctx) -{ + klass = mrb_define_class_under(mrb, module, "Groonga", mrb->object_class); + MRB_SET_INSTANCE_TT(klass, MRB_TT_STRING); } #endif Added: lib/mrb/mrb_obj.h (+34 -0) 100644 =================================================================== --- /dev/null +++ lib/mrb/mrb_obj.h 2013-10-03 18:26:00 +0900 (31d5324) @@ -0,0 +1,34 @@ +/* -*- 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_OBJ_H +#define GRN_MRB_OBJ_H + +#include "../ctx.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void grn_mrb_obj_init(grn_ctx *ctx); + +#ifdef __cplusplus +} +#endif + +#endif /* GRN_MRB_OBJ_H */ Added: lib/mrb/sources.am (+3 -0) 100644 =================================================================== --- /dev/null +++ lib/mrb/sources.am 2013-10-03 18:26:00 +0900 (7a713b6) @@ -0,0 +1,3 @@ +libgrnmrb_la_SOURCES = \ + mrb_obj.c \ + mrb_obj.h Added: test/command/suite/ruby/eval/built_in_class.expected (+4 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/ruby/eval/built_in_class.expected 2013-10-03 18:26:00 +0900 (a4bf725) @@ -0,0 +1,4 @@ +register ruby/eval +[[0,0.0,0.0],true] +ruby_eval "Groonga::Object.to_s" +[[0,0.0,0.0],{"value":"Object"}] Added: test/command/suite/ruby/eval/built_in_class.test (+5 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/ruby/eval/built_in_class.test 2013-10-03 18:26:00 +0900 (e0632b3) @@ -0,0 +1,5 @@ +#@on-error omit +register ruby/eval +#@on-error default + +ruby_eval "Groonga::Object.to_s" -------------- next part -------------- HTML����������������������������...Download