Kouhei Sutou
null+****@clear*****
Sun Jun 8 19:01:14 JST 2014
Kouhei Sutou 2014-06-08 19:01:14 +0900 (Sun, 08 Jun 2014) New Revision: f53a728848040e4bd2410454d033dd0d977ce2e8 https://github.com/groonga/groonga/commit/f53a728848040e4bd2410454d033dd0d977ce2e8 Message: mrb: define Kernel#p Added files: lib/mrb/mrb_kernel.c lib/mrb/mrb_kernel.h lib/mrb/scripts/kernel.rb Modified files: lib/ctx_impl_mrb.c lib/mrb/scripts/sources.am lib/mrb/sources.am Modified: lib/ctx_impl_mrb.c (+2 -0) =================================================================== --- lib/ctx_impl_mrb.c 2014-06-08 18:28:20 +0900 (ba7df47) +++ lib/ctx_impl_mrb.c 2014-06-08 19:01:14 +0900 (e1445c3) @@ -20,6 +20,7 @@ #include "ctx_impl.h" #include "mrb.h" +#include "mrb/mrb_kernel.h" #include "mrb/mrb_ctx.h" #include "mrb/mrb_bulk.h" #include "mrb/mrb_obj.h" @@ -40,6 +41,7 @@ grn_ctx_impl_mrb_init_bindings(grn_ctx *ctx) mrb->ud = ctx; ctx->impl->mrb.module = mrb_define_module(mrb, "Groonga"); + grn_mrb_kernel_init(ctx); grn_mrb_ctx_init(ctx); grn_mrb_bulk_init(ctx); grn_mrb_obj_init(ctx); Added: lib/mrb/mrb_kernel.c (+50 -0) 100644 =================================================================== --- /dev/null +++ lib/mrb/mrb_kernel.c 2014-06-08 19:01:14 +0900 (b40c7f3) @@ -0,0 +1,50 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2014 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 "../mrb.h" +#include "mrb_kernel.h" + +static mrb_value +kernel_print(mrb_state *mrb, mrb_value self) +{ + char *content; + int content_length; + + mrb_get_args(mrb, "s", &content, &content_length); + printf("%.*s", content_length, content); + + return mrb_nil_value(); +} + +void +grn_mrb_kernel_init(grn_ctx *ctx) +{ + grn_mrb_data *data = &(ctx->impl->mrb); + mrb_state *mrb = data->state; + + mrb_define_method(mrb, mrb->kernel_module, + "print", kernel_print, MRB_ARGS_REQ(1)); + + grn_mrb_load(ctx, "kernel.rb"); +} +#endif Added: lib/mrb/mrb_kernel.h (+34 -0) 100644 =================================================================== --- /dev/null +++ lib/mrb/mrb_kernel.h 2014-06-08 19:01:14 +0900 (268509d) @@ -0,0 +1,34 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2014 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_KERNEL_H +#define GRN_MRB_KERNEL_H + +#include "../ctx.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void grn_mrb_kernel_init(grn_ctx *ctx); + +#ifdef __cplusplus +} +#endif + +#endif /* GRN_MRB_KERNEL_H */ Added: lib/mrb/scripts/kernel.rb (+25 -0) 100644 =================================================================== --- /dev/null +++ lib/mrb/scripts/kernel.rb 2014-06-08 19:01:14 +0900 (6626fdd) @@ -0,0 +1,25 @@ +module Kernel + def puts(*arguments) + arguments.each do |argument| + argument = argument.to_s unless argument.is_a?(String) + print(argument) + print("\n") unless argument[argument.size] == "\n" + end + nil + end + + def p(*arguments) + return nil if arguments.empty? + + if arguments.size == 1 + argument = arguments.first + puts(argument.inspect) + argument + else + arguments.each do |argument| + puts(argument.inspect) + end + arguments + end + end +end Modified: lib/mrb/scripts/sources.am (+1 -0) =================================================================== --- lib/mrb/scripts/sources.am 2014-06-08 18:28:20 +0900 (b4f7717) +++ lib/mrb/scripts/sources.am 2014-06-08 19:01:14 +0900 (6f0e559) @@ -2,4 +2,5 @@ RUBY_SCRIPT_FILES = \ eval_context.rb \ expression.rb \ index_info.rb \ + kernel.rb \ scan_info.rb Modified: lib/mrb/sources.am (+2 -0) =================================================================== --- lib/mrb/sources.am 2014-06-08 18:28:20 +0900 (9e4b1bd) +++ lib/mrb/sources.am 2014-06-08 19:01:14 +0900 (96fc28b) @@ -15,6 +15,8 @@ libgrnmrb_la_SOURCES = \ mrb_fixed_size_column.h \ mrb_index_column.c \ mrb_index_column.h \ + mrb_kernel.c \ + mrb_kernel.h \ mrb_obj.c \ mrb_obj.h \ mrb_procedure.c \ -------------- next part -------------- HTML����������������������������... Download