-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplu_global_state.c
57 lines (46 loc) · 1.51 KB
/
plu_global_state.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "plu_global_state.h"
#include "plu_debug.h"
#include "plu_inline.h"
#include "plu_parse_kw.h"
#include "plu_op.h"
#include "plu_lua.h"
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
/* The Lua compiler/interpreter - FIXME ought to be in thread-local storage */
lua_State *PLU_lua_int = NULL;
XOP PLU_xop;
Perl_ophook_t PLU_orig_opfreehook;
/* For chaining the actual keyword plugin */
int (*PLU_next_keyword_plugin)(pTHX_ char *, STRLEN, OP **);
void
plu_init_global_state(pTHX)
{
/* Setup the actual keyword plugin */
PLU_next_keyword_plugin = PL_keyword_plugin;
PL_keyword_plugin = plu_my_keyword_plugin;
/* Setup our callback for cleaning up OPs during global cleanup */
PLU_orig_opfreehook = PL_opfreehook;
PL_opfreehook = plu_op_free_hook;
/* Setup our custom op */
XopENTRY_set(&PLU_xop, xop_name, "luaop");
XopENTRY_set(&PLU_xop, xop_desc, "Inlined Lua Execution");
XopENTRY_set(&PLU_xop, xop_class, OA_BASEOP);
Perl_custom_op_register(aTHX_ plu_pp_custom, &PLU_xop);
/* Init Lua compiler/interpreter */
PLU_lua_int = plu_new_lua_state(aTHX);
/* Register super-late global cleanup hook for global state */
Perl_call_atexit(aTHX_ plu_global_state_final_cleanup, NULL);
}
/* End-of-global-destruction cleanup hook.
* Actually installed in BOOT XS section. */
void
plu_global_state_final_cleanup(pTHX_ void *ptr)
{
(void)ptr;
/*PLU_DEBUG("plu_final_cleanup after global destruction.\n"); */
if (PLU_lua_int != NULL) {
lua_close(PLU_lua_int);
PLU_lua_int = NULL;
}
}