Navigation Menu

Skip to content

Commit

Permalink
plugin mrb: support plugin written by mruby
Browse files Browse the repository at this point in the history
It's experimental feature.
  • Loading branch information
kou committed Jan 5, 2015
1 parent b3b84fb commit 568d8e0
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 56 deletions.
1 change: 1 addition & 0 deletions include/groonga/groonga.h
Expand Up @@ -120,6 +120,7 @@ typedef enum {
GRN_NORMALIZER_ERROR = -72,
GRN_TOKEN_FILTER_ERROR = -73,
GRN_COMMAND_ERROR = -74,
GRN_PLUGIN_ERROR = -75,
} grn_rc;

GRN_API grn_rc grn_init(void);
Expand Down
8 changes: 8 additions & 0 deletions lib/ctx_impl_mrb.c
Expand Up @@ -139,6 +139,8 @@ grn_ctx_impl_mrb_init(grn_ctx *ctx)
ctx->impl->mrb.base_directory[0] = '\0';
ctx->impl->mrb.module = NULL;
ctx->impl->mrb.object_class = NULL;
ctx->impl->mrb.checked_procs = NULL;
ctx->impl->mrb.registered_plugins = NULL;
} else {
ctx->impl->mrb.state = mrb_open();
ctx->impl->mrb.base_directory[0] = '\0';
Expand All @@ -147,6 +149,10 @@ grn_ctx_impl_mrb_init(grn_ctx *ctx)
if (ctx->impl->mrb.state->exc) {
mrb_print_error(ctx->impl->mrb.state);
}
ctx->impl->mrb.checked_procs =
grn_hash_create(ctx, NULL, sizeof(grn_id), 0, GRN_HASH_TINY);
ctx->impl->mrb.registered_plugins =
grn_hash_create(ctx, NULL, sizeof(grn_id), 0, GRN_HASH_TINY);
}
}

Expand All @@ -156,6 +162,8 @@ grn_ctx_impl_mrb_fin(grn_ctx *ctx)
if (ctx->impl->mrb.state) {
mrb_close(ctx->impl->mrb.state);
ctx->impl->mrb.state = NULL;
grn_hash_close(ctx, ctx->impl->mrb.checked_procs);
grn_hash_close(ctx, ctx->impl->mrb.registered_plugins);
}
}
#else
Expand Down
3 changes: 3 additions & 0 deletions lib/db.c
Expand Up @@ -8564,6 +8564,9 @@ grn_ctx_at(grn_ctx *ctx, grn_id id)
}
}
res = vp->ptr;
if (res->header.type == GRN_PROC) {
grn_plugin_ensure_registered(ctx, res);
}
}
}
exit :
Expand Down
2 changes: 2 additions & 0 deletions lib/grn_ctx_impl.h
Expand Up @@ -99,6 +99,8 @@ struct _grn_mrb_data {
char base_directory[PATH_MAX];
struct RClass *module;
struct RClass *object_class;
grn_hash *checked_procs;
grn_hash *registered_plugins;
};
#endif

Expand Down
1 change: 1 addition & 0 deletions lib/grn_plugin.h
Expand Up @@ -52,6 +52,7 @@ grn_rc grn_plugin_close(grn_ctx *ctx, grn_id id);
grn_id grn_plugin_reference(grn_ctx *ctx, const char *filename);
const char *grn_plugin_path(grn_ctx *ctx, grn_id id);
char *grn_plugin_find_path(grn_ctx *ctx, const char *name);
void grn_plugin_ensure_registered(grn_ctx *ctx, grn_obj *proc);

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions lib/mrb/scripts/context/rc.rb
Expand Up @@ -96,6 +96,7 @@ def to_i
NORMALIZER_ERROR = new(:normalizer_error, -72)
TOKEN_FILTER_ERROR = new(:token_filter, -73)
COMMAND_ERROR = new(:command_error, -74)
PLUGIN_ERROR = new(:plugin_error, -75)
end
end
end
2 changes: 2 additions & 0 deletions lib/mrb/scripts/initialize/post.rb
Expand Up @@ -4,4 +4,6 @@
require "command"
require "table_cursor"

require "plugin_loader"

require "eval_context"
14 changes: 14 additions & 0 deletions lib/mrb/scripts/plugin_loader.rb
@@ -0,0 +1,14 @@
module Groonga
class PluginLoader
class << self
def load_file(path)
begin
load(path)
rescue => error
Context.instance.record_error(:plugin_error, error)
nil
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/mrb/scripts/sources.am
Expand Up @@ -14,6 +14,7 @@ RUBY_SCRIPT_FILES = \
initialize/post.rb \
logger.rb \
logger/level.rb \
plugin_loader.rb \
require.rb \
scan_info.rb \
scan_info_builder.rb \
Expand Down

0 comments on commit 568d8e0

Please sign in to comment.