You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bc...@apache.org on 2018/07/31 21:15:46 UTC
[trafficserver] 01/03: Fix bug on loading of lua script
This is an automated email from the ASF dual-hosted git repository.
bcall pushed a commit to branch 8.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 0047d30644613416914d104b6a9f90543cd44799
Author: Kit Chan <ki...@apache.org>
AuthorDate: Tue Jul 10 00:13:46 2018 -0700
Fix bug on loading of lua script
(cherry picked from commit 3c0c413321d8fa59cbb4cc8f9e5ddbd9d5b04e98)
---
plugins/lua/ts_lua.c | 8 +++++---
plugins/lua/ts_lua_common.h | 2 ++
plugins/lua/ts_lua_util.c | 3 +++
3 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/plugins/lua/ts_lua.c b/plugins/lua/ts_lua.c
index bd8cec2..cbfc782 100644
--- a/plugins/lua/ts_lua.c
+++ b/plugins/lua/ts_lua.c
@@ -133,8 +133,9 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int errbuf_s
}
memset(conf, 0, sizeof(ts_lua_instance_conf));
- conf->states = states;
- conf->remap = 1;
+ conf->states = states;
+ conf->remap = 1;
+ conf->init_func = 0;
if (fn) {
snprintf(conf->script, TS_LUA_MAX_SCRIPT_FNAME_LENGTH, "%s", argv[optind]);
@@ -150,7 +151,8 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int errbuf_s
return TS_ERROR;
}
- if (fn) {
+ // register the script only if it is from a file and has no __init__ function
+ if (fn && !conf->init_func) {
// we only need to register the script for the first lua VM
ts_lua_script_register(ts_lua_main_ctx_array[0].lua, conf->script, conf);
}
diff --git a/plugins/lua/ts_lua_common.h b/plugins/lua/ts_lua_common.h
index e355e03..0115f0e 100644
--- a/plugins/lua/ts_lua_common.h
+++ b/plugins/lua/ts_lua_common.h
@@ -96,6 +96,8 @@ typedef struct {
int remap;
int states;
+
+ int init_func;
} ts_lua_instance_conf;
/* lua state for http request */
diff --git a/plugins/lua/ts_lua_util.c b/plugins/lua/ts_lua_util.c
index cb7d8c0..9455c1b 100644
--- a/plugins/lua/ts_lua_util.c
+++ b/plugins/lua/ts_lua_util.c
@@ -227,6 +227,9 @@ ts_lua_add_module(ts_lua_instance_conf *conf, ts_lua_main_ctx *arr, int n, int a
lua_getglobal(L, "__init__");
if (lua_type(L, -1) == LUA_TFUNCTION) {
+ // specifying that the file has an __init__ function
+ conf->init_func = 1;
+
lua_newtable(L);
for (t = 0; t < argc; t++) {