Yasuhiro Horimoto 2019-05-24 12:48:14 +0900 (Fri, 24 May 2019) Revision: 4a1aebe3296a88fe2faa32be68a0b4373e6e9b56 https://github.com/groonga/groonga/commit/4a1aebe3296a88fe2faa32be68a0b4373e6e9b56 Message: ctx: add support lua vm (#968) * ctx: add support lua vm However, currently, this feature is just only initialized the lua vm and remove the lua vm when groonga finish. * c_sources.am: sort by alphabetical order * ctx: modify call order that reverse order of initialization * ctx: remove a needless definition * ctx: remove a needless header Added files: lib/ctx_impl_lua.c lib/grn_ctx_impl_lua.h Modified files: lib/c_sources.am lib/ctx.c lib/grn_ctx_impl.h Modified: lib/c_sources.am (+70 -68) =================================================================== --- lib/c_sources.am 2019-05-24 09:50:48 +0900 (14247a911) +++ lib/c_sources.am 2019-05-24 12:48:14 +0900 (541cee5ec) @@ -1,138 +1,140 @@ libgroonga_c_sources = \ accessor.c \ alloc.c \ - grn_alloc.h \ cache.c \ - grn_cache.h \ column.c \ - grn_column.h \ com.c \ - grn_com.h \ command.c \ config.c \ - grn_config.h \ ctx.c \ + ctx_impl_lua.c \ + ctx_impl_mrb.c \ + db.c \ + dump.c \ + encoding.c \ + error.c \ + expr.c \ + expr_code.c \ + expr_executor.c \ + file_lock.c \ + file_reader.c \ + geo.c \ + grn.h \ + grn_alloc.h \ + grn_cache.h \ + grn_column.h \ + grn_com.h \ + grn_config.h \ grn_ctx.h \ grn_ctx_impl.h \ - ctx_impl_mrb.c \ + grn_ctx_impl_lua.h \ grn_ctx_impl_mrb.h \ grn_dat.h \ - db.c \ grn_db.h \ - dump.c \ - encoding.c \ grn_encoding.h \ - ts.c \ - grn_ts.h \ - type.c \ - error.c \ grn_error.h \ - expr.c \ grn_expr.h \ - expr_code.c \ grn_expr_code.h \ - expr_executor.c \ grn_expr_executor.h \ - file_lock.c \ grn_file_lock.h \ - geo.c \ grn_geo.h \ - grn.h \ - hash.c \ grn_hash.h \ + grn_ii.h \ + grn_index_column.h \ + grn_io.h \ + grn_load.h \ + grn_logger.h \ + grn_mrb.h \ + grn_msgpack.h \ + grn_nfkc.h \ + grn_normalizer.h \ + grn_obj.h \ + grn_onigmo.h \ + grn_options.h \ + grn_output.h \ + grn_output_columns.h \ + grn_pat.h \ + grn_plugin.h \ + grn_proc.h \ + grn_report.h \ + grn_request_canceler.h \ + grn_request_timer.h \ + grn_romaji.h \ + grn_rset.h \ + grn_scanner.h \ + grn_scorer.h \ + grn_scorers.h \ + grn_snip.h \ + grn_store.h \ + grn_str.h \ + grn_string.h \ + grn_table.h \ + grn_time.h \ + grn_token.h \ + grn_token_cursor.h \ + grn_token_filters.h \ + grn_token_metadata.h \ + grn_tokenizer.h \ + grn_tokenizers.h \ + grn_ts.h \ + grn_util.h \ + grn_window_function.h \ + grn_window_function_executor.h \ + grn_window_functions.h \ + grn_windows.h \ + hash.c \ highlighter.c \ id.c \ ii.c \ - grn_ii.h \ index_column.c \ - grn_index_column.h \ io.c \ - grn_io.h \ load.c \ - grn_load.h \ logger.c \ - grn_logger.h \ memory.c \ mrb.c \ - grn_mrb.h \ msgpack.c \ - grn_msgpack.h \ nfkc.c \ - grn_nfkc.h \ - nfkc50.c \ nfkc100.c \ nfkc121.c \ + nfkc50.c \ normalizer.c \ - grn_normalizer.h \ obj.c \ - grn_obj.h \ onigmo.c \ - grn_onigmo.h \ operator.c \ options.c \ - grn_options.h \ output.c \ - grn_output.h \ output_columns.c \ - grn_output_columns.h \ pat.c \ - grn_pat.h \ plugin.c \ - grn_plugin.h \ proc.c \ - grn_proc.h \ raw_string.c \ report.c \ - grn_report.h \ request_canceler.c \ - grn_request_canceler.h \ request_timer.c \ - grn_request_timer.h \ romaji.c \ - grn_romaji.h \ rset.c \ - grn_rset.h \ scanner.c \ - grn_scanner.h \ scorer.c \ - grn_scorer.h \ scorers.c \ - grn_scorers.h \ snip.c \ - grn_snip.h \ store.c \ - grn_store.h \ str.c \ - grn_str.h \ string.c \ - grn_string.h \ table.c \ - grn_table.h \ thread.c \ time.c \ - grn_time.h \ token.c \ - grn_token.h \ token_cursor.c \ - grn_token_cursor.h \ + token_filter.c \ + token_filters.c \ token_metadata.c \ - grn_token_metadata.h \ tokenizer.c \ - grn_tokenizer.h \ tokenizers.c \ - grn_tokenizers.h \ - token_filter.c \ - token_filters.c \ - grn_token_filters.h \ + ts.c \ + type.c \ util.c \ - grn_util.h \ - windows.c \ - grn_windows.h \ - windows_event_logger.c \ - file_reader.c \ window_function.c \ - grn_window_function.h \ window_function_executor.c \ - grn_window_function_executor.h \ window_functions.c \ - grn_window_functions.h + windows.c \ + windows_event_logger.c Modified: lib/ctx.c (+3 -0) =================================================================== --- lib/ctx.c 2019-05-24 09:50:48 +0900 (ec66840e7) +++ lib/ctx.c 2019-05-24 12:48:14 +0900 (1d38ddc96) @@ -33,6 +33,7 @@ #include "grn_normalizer.h" #include "grn_mrb.h" #include "grn_ctx_impl_mrb.h" +#include "grn_ctx_impl_lua.h" #include "grn_logger.h" #include "grn_cache.h" #include "grn_expr.h" @@ -315,6 +316,7 @@ grn_ctx_impl_init(grn_ctx *ctx) ctx->impl->n_same_error_messages = 0; grn_ctx_impl_mrb_init(ctx); + grn_ctx_impl_lua_init(ctx); GRN_TEXT_INIT(&(ctx->impl->temporary_open_spaces.stack), 0); ctx->impl->temporary_open_spaces.current = NULL; @@ -421,6 +423,7 @@ grn_ctx_impl_fin(grn_ctx *ctx) } GRN_OBJ_FIN(ctx, stack); } + grn_ctx_impl_lua_fin(ctx); grn_ctx_impl_mrb_fin(ctx); grn_ctx_loader_clear(ctx); if (ctx->impl->parser) { Added: lib/ctx_impl_lua.c (+69 -0) 100644 =================================================================== --- /dev/null +++ lib/ctx_impl_lua.c 2019-05-24 12:48:14 +0900 (dbecf4523) @@ -0,0 +1,69 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2019 Yasuhiro Horimoto <horim****@clear*****> + + 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 "grn_ctx_impl.h" +#include "grn_ctx_impl_lua.h" + +#ifdef GRN_WITH_LUAJIT +static void +grn_ctx_impl_lua_init_real(grn_ctx *ctx) +{ + lua_State *lua; + + lua = lua_open(); + luaL_openlibs(lua); + ctx->impl->lua.state = lua; +} + +static void +grn_ctx_impl_lua_fin_real(grn_ctx * ctx) +{ + if (ctx->impl->lua.state) { + lua_close(ctx->impl->lua.state); + ctx->impl->lua.state = NULL; + } +} +#else /* GRN_WITH_LUAJIT */ +static void +grn_ctx_impl_lua_init_real(grn_ctx *ctx) +{ +} + +static void +grn_ctx_impl_lua_fin_real(grn_ctx *ctx) +{ +} +#endif /* GRN_WITH_LUAJIT */ + +void +grn_ctx_impl_lua_init(grn_ctx *ctx) +{ + ctx->impl->lua.initialized = GRN_TRUE; + grn_ctx_impl_lua_init_real(ctx); +} + +void +grn_ctx_impl_lua_fin(grn_ctx *ctx) +{ + if (!ctx->impl->lua.initialized) { + return; + } + + ctx->impl->lua.initialized = GRN_FALSE; + grn_ctx_impl_lua_fin_real(ctx); +} Modified: lib/grn_ctx_impl.h (+14 -0) =================================================================== --- lib/grn_ctx_impl.h 2019-05-24 09:50:48 +0900 (3b462bedc) +++ lib/grn_ctx_impl.h 2019-05-24 12:48:14 +0900 (8b7225f47) @@ -28,6 +28,11 @@ # include <mruby.h> #endif +#ifdef GRN_WITH_LUAJIT +# include <lauxlib.h> +# include <lualib.h> +#endif + #ifdef __cplusplus extern "C" { #endif @@ -137,6 +142,14 @@ struct _grn_mrb_data { #endif }; +typedef struct _grn_lua_data grn_lua_data; +struct _grn_lua_data { + grn_bool initialized; +#ifdef GRN_WITH_LUAJIT + lua_State *state; +#endif +}; + struct _grn_ctx_impl { grn_encoding encoding; @@ -219,6 +232,7 @@ struct _grn_ctx_impl { unsigned int n_same_error_messages; grn_mrb_data mrb; + grn_lua_data lua; struct { grn_obj stack; Added: lib/grn_ctx_impl_lua.h (+33 -0) 100644 =================================================================== --- /dev/null +++ lib/grn_ctx_impl_lua.h 2019-05-24 12:48:14 +0900 (637221708) @@ -0,0 +1,33 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2019 Yasuhiro Horimoto <horim****@clear*****> + + 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 +*/ + +#pragma once + +#include "grn.h" +#include "grn_ctx.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void grn_ctx_impl_lua_init(grn_ctx *ctx); +void grn_ctx_impl_lua_fin(grn_ctx *ctx); + +#ifdef __cplusplus +} +#endif -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190524/d0b930e2/attachment-0001.html>