Debian Codegraph @

lib/ctx_impl_lua.c

raw symbols SCIP
1 /*
2 Copyright(C) 2019 Yasuhiro Horimoto <[email protected]>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
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 "grn_ctx_impl.h"
20 #include "grn_ctx_impl_lua.h"
21
22 #ifdef GRN_WITH_LUAJIT
23 static void
24 grn_ctx_impl_lua_init_real(grn_ctx *ctx)
25 {
26 lua_State *lua;
27
28 lua = lua_open();
29 luaL_openlibs(lua);
30 ctx->impl->lua.state = lua;
31 }
32
33 static void
34 grn_ctx_impl_lua_fin_real(grn_ctx * ctx)
35 {
36 if (ctx->impl->lua.state) {
37 lua_close(ctx->impl->lua.state);
38 ctx->impl->lua.state = NULL;
39 }
40 }
41 #else /* GRN_WITH_LUAJIT */
42 static void
43 grn_ctx_impl_lua_init_real(grn_ctx *ctx)
44 {
45 }
46
47 static void
48 grn_ctx_impl_lua_fin_real(grn_ctx *ctx)
49 {
50 }
51 #endif /* GRN_WITH_LUAJIT */
52
53 void
54 grn_ctx_impl_lua_init(grn_ctx *ctx)
55 {
56 ctx->impl->lua.initialized = true;
57 grn_ctx_impl_lua_init_real(ctx);
58 }
59
60 void
61 grn_ctx_impl_lua_fin(grn_ctx *ctx)
62 {
63 if (!ctx->impl->lua.initialized) {
64 return;
65 }
66
67 ctx->impl->lua.initialized = false;
68 grn_ctx_impl_lua_fin_real(ctx);
69 }