1
/* vim:set ft=c ts=4 sw=4 et fdm=marker: */
2
#include "ngx_http_lua_conf.h"
3
#include "ngx_http_lua_util.h"
6
static void ngx_http_lua_cleanup_vm(void *data);
7
static char * ngx_http_lua_init_vm(ngx_conf_t *cf, ngx_http_lua_main_conf_t *lmcf);
11
ngx_http_lua_create_main_conf(ngx_conf_t *cf)
13
ngx_http_lua_main_conf_t *lmcf;
15
lmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_lua_main_conf_t));
20
/* set by ngx_pcalloc:
22
* lmcf->lua_path = { 0, NULL };
23
* lmcf->lua_cpath = { 0, NULL };
26
dd("NginX Lua module main config structure initialized!");
33
ngx_http_lua_init_main_conf(ngx_conf_t *cf, void *conf)
35
ngx_http_lua_main_conf_t *lmcf = conf;
37
if (lmcf->lua == NULL) {
38
if (ngx_http_lua_init_vm(cf, lmcf) != NGX_CONF_OK) {
39
ngx_conf_log_error(NGX_ERROR, cf, 0, "Failed to initialize Lua VM!");
40
return NGX_CONF_ERROR;
43
dd("Lua VM initialized!");
51
ngx_http_lua_create_loc_conf(ngx_conf_t *cf)
53
ngx_http_lua_loc_conf_t *conf;
55
conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_lua_loc_conf_t));
57
return NGX_CONF_ERROR;
60
/* set by ngx_pcalloc:
61
* conf->src = { 0, NULL };
64
conf->force_read_body = NGX_CONF_UNSET;
71
ngx_http_lua_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
73
ngx_http_lua_loc_conf_t *prev = parent;
74
ngx_http_lua_loc_conf_t *conf = child;
76
ngx_conf_merge_str_value(conf->src, prev->src, "");
77
ngx_conf_merge_value(conf->force_read_body, prev->force_read_body, 0);
84
ngx_http_lua_cleanup_vm(void *data)
86
lua_State *lua = data;
97
ngx_http_lua_init_vm(ngx_conf_t *cf, ngx_http_lua_main_conf_t *lmcf)
99
ngx_pool_cleanup_t *cln;
101
/* add new cleanup handler to config mem pool */
102
cln = ngx_pool_cleanup_add(cf->pool, 0);
104
return NGX_CONF_ERROR;
107
/* create new Lua VM instance */
108
lmcf->lua = ngx_http_lua_new_state(cf, lmcf);
109
if (lmcf->lua == NULL) {
110
return NGX_CONF_ERROR;
113
/* register cleanup handler for Lua VM */
114
cln->handler = ngx_http_lua_cleanup_vm;
115
cln->data = lmcf->lua;