Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ruby_plugin.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  Copyright(C) 2013 Brazil
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License version 2.1 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include <mrb.h>
20 #include <output.h>
21 #include <db.h>
22 #include <ctx_impl.h>
23 #include <util.h>
24 
25 #include <groonga/plugin.h>
26 
27 #include <mruby.h>
28 
29 #define VAR GRN_PROC_GET_VAR_BY_OFFSET
30 
31 static void
32 output_result(grn_ctx *ctx, mrb_value result)
33 {
34  mrb_state *mrb = ctx->impl->mrb.state;
35 
36  GRN_OUTPUT_MAP_OPEN("result", 1);
37  if (mrb->exc) {
38  mrb_value mrb_message;
39  grn_obj grn_message;
40  GRN_OUTPUT_CSTR("exception");
41  GRN_OUTPUT_MAP_OPEN("exception", 1);
42  GRN_OUTPUT_CSTR("message");
43  mrb_message = mrb_funcall(mrb, mrb_obj_value(mrb->exc), "message", 0);
44  GRN_VOID_INIT(&grn_message);
45  if (grn_mrb_to_grn(ctx, mrb_message, &grn_message) == GRN_SUCCESS) {
46  GRN_OUTPUT_OBJ(&grn_message, NULL);
47  } else {
48  GRN_OUTPUT_CSTR("unsupported message type");
49  }
50  grn_obj_unlink(ctx, &grn_message);
52  } else {
53  grn_obj grn_result;
54  GRN_OUTPUT_CSTR("value");
55  GRN_VOID_INIT(&grn_result);
56  if (grn_mrb_to_grn(ctx, result, &grn_result) == GRN_SUCCESS) {
57  GRN_OUTPUT_OBJ(&grn_result, NULL);
58  } else {
59  GRN_OUTPUT_CSTR("unsupported return value");
60  }
61  grn_obj_unlink(ctx, &grn_result);
62  }
64 }
65 
66 grn_rc
68 {
69  return GRN_SUCCESS;
70 }
71 
72 #define DEF_VAR(v,x) do {\
73  (v).name = (x);\
74  (v).name_size = (x) ? sizeof(x) - 1 : 0;\
75  GRN_TEXT_INIT(&(v).value, 0);\
76 } while (0)
77 
78 #define DEF_COMMAND(name, func, nvars, vars)\
79  (grn_proc_create(ctx, (name), (sizeof(name) - 1),\
80  GRN_PROC_COMMAND, (func), NULL, NULL, (nvars), (vars)))
81 
82 grn_rc
84 {
85  return GRN_SUCCESS;
86 }