Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
load.c
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 "ruby_plugin.h"
20 
21 static grn_obj *
22 command_ruby_load(grn_ctx *ctx, int nargs, grn_obj **args,
23  grn_user_data *user_data)
24 {
25  grn_obj *path;
26  mrb_value result;
27 
28  path = VAR(0);
29  switch (path->header.domain) {
30  case GRN_DB_SHORT_TEXT :
31  case GRN_DB_TEXT :
32  case GRN_DB_LONG_TEXT :
33  break;
34  default :
35  {
36  grn_obj inspected;
37  GRN_TEXT_INIT(&inspected, 0);
38  grn_inspect(ctx, &inspected, path);
39  ERR(GRN_INVALID_ARGUMENT, "path must be a string: <%.*s>",
40  (int)GRN_TEXT_LEN(&inspected), GRN_TEXT_VALUE(&inspected));
41  GRN_OBJ_FIN(ctx, &inspected);
42  return NULL;
43  }
44  break;
45  }
46 
47  GRN_TEXT_PUTC(ctx, path, '\0');
48  result = grn_mrb_load(ctx, GRN_TEXT_VALUE(path));
49  output_result(ctx, result);
50 
51  return NULL;
52 }
53 
54 grn_rc
56 {
57  grn_expr_var vars[1];
58 
59  DEF_VAR(vars[0], "path");
60  DEF_COMMAND("ruby_load", command_ruby_load, 1, vars);
61 
62  return ctx->rc;
63 }