Kouhei Sutou
null+****@clear*****
Thu Aug 7 23:46:44 JST 2014
Kouhei Sutou 2014-08-07 23:46:44 +0900 (Thu, 07 Aug 2014) New Revision: 6fc262dce1822b5407234ea2e4f50a8371b21d46 https://github.com/groonga/groonga/commit/6fc262dce1822b5407234ea2e4f50a8371b21d46 Message: mruby: support setting error message Modified files: lib/mrb/mrb_ctx.c Modified: lib/mrb/mrb_ctx.c (+26 -0) =================================================================== --- lib/mrb/mrb_ctx.c 2014-08-07 23:46:13 +0900 (2c3ac68) +++ lib/mrb/mrb_ctx.c 2014-08-07 23:46:44 +0900 (81a584d) @@ -157,6 +157,28 @@ ctx_set_error_method(mrb_state *mrb, mrb_value self) return error_method; } +static mrb_value +ctx_get_error_message(mrb_state *mrb, mrb_value self) +{ + grn_ctx *ctx = (grn_ctx *)mrb->ud; + + return mrb_str_new_cstr(mrb, ctx->errbuf); +} + +static mrb_value +ctx_set_error_message(mrb_state *mrb, mrb_value self) +{ + grn_ctx *ctx = (grn_ctx *)mrb->ud; + mrb_value error_message; + + mrb_get_args(mrb, "S", &error_message); + grn_ctx_log(ctx, "%.*s", + RSTRING_LEN(error_message), + RSTRING_PTR(error_message)); + + return error_message; +} + void grn_mrb_ctx_init(grn_ctx *ctx) { @@ -190,6 +212,10 @@ grn_mrb_ctx_init(grn_ctx *ctx) MRB_ARGS_NONE()); mrb_define_method(mrb, klass, "error_method=", ctx_set_error_method, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, klass, "error_message", ctx_get_error_message, + MRB_ARGS_NONE()); + mrb_define_method(mrb, klass, "error_message=", ctx_set_error_message, + MRB_ARGS_REQ(1)); grn_mrb_load(ctx, "context/error_level.rb"); grn_mrb_load(ctx, "context/rc.rb"); -------------- next part -------------- HTML����������������������������... Télécharger