summaryrefslogtreecommitdiff
path: root/storage/mroonga/vendor/groonga/plugins/ruby/load.c
diff options
context:
space:
mode:
Diffstat (limited to 'storage/mroonga/vendor/groonga/plugins/ruby/load.c')
-rw-r--r--storage/mroonga/vendor/groonga/plugins/ruby/load.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/storage/mroonga/vendor/groonga/plugins/ruby/load.c b/storage/mroonga/vendor/groonga/plugins/ruby/load.c
new file mode 100644
index 00000000000..a4e60acc357
--- /dev/null
+++ b/storage/mroonga/vendor/groonga/plugins/ruby/load.c
@@ -0,0 +1,63 @@
+/* -*- c-basic-offset: 2; indent-tabs-mode: nil -*- */
+/*
+ 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
+*/
+
+#include "ruby_plugin.h"
+
+static grn_obj *
+command_ruby_load(grn_ctx *ctx, int nargs, grn_obj **args,
+ grn_user_data *user_data)
+{
+ grn_obj *path;
+ mrb_value result;
+
+ path = VAR(0);
+ switch (path->header.domain) {
+ case GRN_DB_SHORT_TEXT :
+ case GRN_DB_TEXT :
+ case GRN_DB_LONG_TEXT :
+ break;
+ default :
+ {
+ grn_obj inspected;
+ GRN_TEXT_INIT(&inspected, 0);
+ grn_inspect(ctx, &inspected, path);
+ ERR(GRN_INVALID_ARGUMENT, "path must be a string: <%.*s>",
+ (int)GRN_TEXT_LEN(&inspected), GRN_TEXT_VALUE(&inspected));
+ GRN_OBJ_FIN(ctx, &inspected);
+ return NULL;
+ }
+ break;
+ }
+
+ GRN_TEXT_PUTC(ctx, path, '\0');
+ result = grn_mrb_load(ctx, GRN_TEXT_VALUE(path));
+ output_result(ctx, result);
+
+ return NULL;
+}
+
+grn_rc
+GRN_PLUGIN_REGISTER(grn_ctx *ctx)
+{
+ grn_expr_var vars[1];
+
+ grn_plugin_expr_var_init(ctx, &vars[0], "path", -1);
+ grn_plugin_command_create(ctx, "ruby_load", -1, command_ruby_load, 1, vars);
+
+ return ctx->rc;
+}