summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorniubinghui <[email protected]>2024-08-07 16:56:56 +0800
committerniubinghui <[email protected]>2024-08-07 16:56:56 +0800
commit2a56bed6fe6aef10b21e3c7be1680daccab05c95 (patch)
treebdf3fb778f8f91989335cf0b084354939c5ac10e
parentfb9df743998c7eb20cd9803b2fcbb52d0c35dbb1 (diff)
【修改】BugFIX:多个lua脚本中的重名函数可能导致加载错误
-rw-r--r--src/lua_plugin_manage.c5
-rw-r--r--src/lua_plugin_manage_internal.h9
2 files changed, 14 insertions, 0 deletions
diff --git a/src/lua_plugin_manage.c b/src/lua_plugin_manage.c
index 3543444..3f6b458 100644
--- a/src/lua_plugin_manage.c
+++ b/src/lua_plugin_manage.c
@@ -359,6 +359,7 @@ int plugin_env_instance_init(
memset(plugin_env, 0, sizeof(struct lua_plugin_env));
plugin_env->plugin_env_state = state;
plugin_env->plugin_env_plugin_array = NULL;
+ plugin_env->plugin_env_filepath = strdup(specific->config_specific_file);
// plugin_env->plugin_env_name = strdup(specific->config_specific_name);
/* 从文件中加载load函数, 但此时不调用 */
if (script_instance_init_byname(&plugin_env->plugin_env_load_func,
@@ -409,6 +410,8 @@ void plugin_env_instance_destory(void *elt)
/* 释放已经注册的插件 */
if (plugin_env->plugin_env_plugin_array)
utarray_free(plugin_env->plugin_env_plugin_array);
+ if (plugin_env->plugin_env_filepath)
+ free(plugin_env->plugin_env_filepath);
/* 释放插件的加载函数与卸载函数 */
script_instance_clean(&plugin_env->plugin_env_load_func);
@@ -520,6 +523,8 @@ int thread_state_instance_load(
lua_pushlightuserdata(state, plugin_env);
lua_setfield(state, -2, PLUGIN_ENV_DEFAULT_KEY);
lua_settop(state, 0);
+ luaL_loadfile(state, plugin_env->plugin_env_filepath);
+ lua_pcall(state, 0, 0, 0);
struct lua_cdata param[2];
param[0].cdata_type = DATATYPE_POINTER;
diff --git a/src/lua_plugin_manage_internal.h b/src/lua_plugin_manage_internal.h
index 3aeab47..ae74864 100644
--- a/src/lua_plugin_manage_internal.h
+++ b/src/lua_plugin_manage_internal.h
@@ -64,6 +64,11 @@
*
* void *lpm_ctx_new_func;
* void lpm_ctx_free_func;
+ *
+ * 08-07
+ * BugFix:
+ * 修改struct lua_plugin_env, 其中增加文件路径
+ * 防止在加载过程中由于函数重名导致的加载错误
************************************************************************/
#ifndef LUA_PLUGIN_MANAGE_INTERNAL_H
#define LUA_PLUGIN_MANAGE_INTERNAL_H
@@ -278,6 +283,10 @@ struct lua_plugin_env
/* 插件申请lua内的全局变量可以保存在该命名空间内, 防止被其他内容覆盖 */
// char *plugin_env_name;
+ /* bugfix */
+ /* 增加文件路径, 防止在加载过程中出现重名的情况导致加载错误 */
+ char * plugin_env_filepath;
+
/* 在lua中保存运行数据的引用ID */
int plugin_env_ref_id; /* plugin_env */
};