【优化】修改部分函数定义位置,减少内部接口函数
This commit is contained in:
@@ -43,6 +43,15 @@ struct lua_binding_data lua_bind_datas[] = {
|
||||
{DATATYPE_END, NULL, NULL, NULL},
|
||||
};
|
||||
|
||||
/* 向lua状态机中注册一个函数 */
|
||||
int lua_cbinding_function(lua_State *state, lua_CFunction bind_function, const char *function_name, const char *space_name);
|
||||
/* 从lua状态机中移除一个已经注册的函数 */
|
||||
int lua_cbinding_function_remove(lua_State *state, const char *function_name, const char *space_name);
|
||||
/* 将一个全局数据注册至状态机中 */
|
||||
int lua_cbinding_data(lua_State *state, struct lua_binding_data *data);
|
||||
/* 从状态机中移除一个已经注册的全局数据 */
|
||||
int lua_cbinding_data_remove(lua_State *state, const char *data_name, const char *space_name);
|
||||
|
||||
/*
|
||||
* Function: lua_cbinding_function
|
||||
* Input: | lua_State * | state | 需要注册函数的状态机
|
||||
@@ -481,7 +490,7 @@ int lua_plugin_manage_session_regist(lua_State *state)
|
||||
}
|
||||
|
||||
/* 取出处理第四个参数 */
|
||||
struct lua_plugin_env *plugin_env = (struct lua_plugin_env *)lua_topointer(state, -1);
|
||||
struct lua_plugin_env *plugin_env = (struct lua_plugin_env *)lua_topointer(state, -1); /* stack 4 */
|
||||
if (!plugin_env)
|
||||
{
|
||||
lua_settop(state, 0);
|
||||
@@ -490,39 +499,43 @@ int lua_plugin_manage_session_regist(lua_State *state)
|
||||
lua_pop(state, 1);
|
||||
|
||||
/* 取出处理第三个参数 */
|
||||
int ctx_free_id = luaL_ref(state, LUA_REGISTRYINDEX);
|
||||
int ctx_free_id = luaL_ref(state, LUA_REGISTRYINDEX); /* stack 3 */
|
||||
if (ctx_free_id == LUA_REFNIL)
|
||||
{
|
||||
lua_settop(state, 0);
|
||||
return 0;
|
||||
}
|
||||
lua_pop(state, 1);
|
||||
|
||||
/* 取出处理第二个参数 */
|
||||
int ctx_new_id = luaL_ref(state, LUA_REGISTRYINDEX);
|
||||
int ctx_new_id = luaL_ref(state, LUA_REGISTRYINDEX); /* stack 2 */
|
||||
if (ctx_new_id == LUA_REFNIL)
|
||||
{
|
||||
lua_settop(state, 0);
|
||||
return 0;
|
||||
}
|
||||
lua_pop(state, 1);
|
||||
|
||||
/* 取出处理第一个参数 */
|
||||
struct stellar * st = (struct stellar *)lua_topointer(state, -1);
|
||||
struct stellar * st = (struct stellar *)lua_topointer(state, -1); /* stack 1 */
|
||||
if ( !st ) {
|
||||
lua_settop(state, 0);
|
||||
return 0;
|
||||
}
|
||||
lua_pop(state, 1);
|
||||
|
||||
/* 在stellar中注册, 获取注册id */
|
||||
int plugin_id = stellar_session_plugin_register(st, lpm_ctx_new_func, lpm_ctx_free_func, (void *)plugin_env);
|
||||
|
||||
#ifdef LUAPLUGIN_BASIC_UNITTEST
|
||||
printf("now regist new plugin, plugin id is %d\n", plugin_id);
|
||||
#endif
|
||||
|
||||
/* 将注册完成的新插件插入到队列中 */
|
||||
struct lua_session_plugin session_plugin;
|
||||
memset(&session_plugin, 0, sizeof(session_plugin));
|
||||
session_plugin_instance_init(&session_plugin, state, plugin_id, ctx_new_id, ctx_free_id);
|
||||
|
||||
utarray_push_back(plugin_env->plugin_env_plugin_array, &session_plugin);
|
||||
|
||||
lua_settop(state, 0);
|
||||
lua_pushinteger(state, plugin_id);
|
||||
|
||||
return 1;
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
* int thread_state_instance_load;
|
||||
* int lua_plugin_manage_config_load;
|
||||
* int lua_plugin_manage_thread_load;
|
||||
*
|
||||
*
|
||||
* 08-06
|
||||
* 完成数据相关操作, 并补全函数script_execute
|
||||
* 完成注册至C插件管理器中的session_ctx_new_func及session_ctx_free_func函数
|
||||
@@ -61,7 +61,7 @@
|
||||
* struct lua_context * lua_context_new;
|
||||
* int lua_context_push_stack;
|
||||
* void lua_context_free;
|
||||
*
|
||||
*
|
||||
* void *lpm_ctx_new_func;
|
||||
* void lpm_ctx_free_func;
|
||||
************************************************************************/
|
||||
@@ -95,11 +95,6 @@ struct lua_binding_function
|
||||
/* 所有需要注册至lua状态机中供lua调用的函数 */
|
||||
extern struct lua_binding_function lua_bind_functions[];
|
||||
|
||||
/* 向lua状态机中注册一个函数 */
|
||||
int lua_cbinding_function(lua_State *state, lua_CFunction bind_function, const char *function_name, const char *space_name);
|
||||
/* 从lua状态机中移除一个已经注册的函数 */
|
||||
int lua_cbinding_function_remove(lua_State *state, const char *function_name, const char *space_name);
|
||||
|
||||
/* 暂时支持前四种数据类型提前注册至lua状态机中 */
|
||||
/* 其余类型用于运行lua函数等场景 */
|
||||
enum DATATYPE
|
||||
@@ -141,11 +136,6 @@ struct lua_binding_data
|
||||
/* 所有需要注册至lua状态机中的全局数据 */
|
||||
extern struct lua_binding_data lua_bind_datas[];
|
||||
|
||||
/* 将一个全局数据注册至状态机中 */
|
||||
int lua_cbinding_data(lua_State *state, struct lua_binding_data *data);
|
||||
/* 从状态机中移除一个已经注册的全局数据 */
|
||||
int lua_cbinding_data_remove(lua_State *state, const char *data_name, const char *space_name);
|
||||
|
||||
/* 将lua_bind_functions中提前注册的所有函数注册至state状态机中 */
|
||||
int lua_cbinding_functions(lua_State *state);
|
||||
/* 将lua_bind_datas中提前注册的所有数据注册至state状态机中 */
|
||||
@@ -158,39 +148,48 @@ struct lua_cdata;
|
||||
struct lua_context;
|
||||
|
||||
/* 保存lua数据的结构 */
|
||||
struct lua_cdata {
|
||||
struct lua_cdata
|
||||
{
|
||||
enum DATATYPE cdata_type;
|
||||
union {
|
||||
union
|
||||
{
|
||||
int cdata_bool;
|
||||
int cdata_int;
|
||||
double cdata_num;
|
||||
char * cdata_string;
|
||||
char *cdata_string;
|
||||
/* table暂时只有plugin_env场景下使用, 暂时使用索引进行操作 */
|
||||
int cdata_table;
|
||||
void * cdata_pointer;
|
||||
struct lua_context * cdata_context;
|
||||
void *cdata_pointer;
|
||||
struct lua_context *cdata_context;
|
||||
};
|
||||
};
|
||||
|
||||
/* 将一个data结构入栈 */
|
||||
int lua_cdata_push_stack(lua_State * state, struct lua_cdata * cdata);
|
||||
int lua_cdata_push_stack(lua_State *state, struct lua_cdata *cdata);
|
||||
/* 从栈中弹出一个元素, 并保存在data结构中 */
|
||||
int lua_cdata_pop_stack(lua_State * state, struct lua_cdata * cdata);
|
||||
int lua_cdata_pop_stack(lua_State *state, struct lua_cdata *cdata);
|
||||
/* 销毁一个data结构, 只有string类型需要调用此函数, 其他的情况直接释放即可 */
|
||||
void lua_cdata_destory(struct lua_cdata * cdata);
|
||||
void lua_cdata_destory(struct lua_cdata *cdata);
|
||||
|
||||
/* 上下文结构, 保存临时数据 */
|
||||
struct lua_context {
|
||||
lua_State * context_state;
|
||||
struct lua_context
|
||||
{
|
||||
lua_State *context_state;
|
||||
int context_ref_id;
|
||||
};
|
||||
|
||||
/* 在状态机中生成一个context */
|
||||
struct lua_context * lua_context_new(lua_State * state);
|
||||
struct lua_context *lua_context_new(lua_State *state);
|
||||
/* 将一个context入栈 */
|
||||
int lua_context_push_stack(struct lua_context * context);
|
||||
int lua_context_push_stack(struct lua_context *context);
|
||||
/* 释放一个context */
|
||||
void lua_context_free(struct lua_context * context);
|
||||
void lua_context_free(struct lua_context *context);
|
||||
|
||||
/* ***** ***** ***** ***** ***** ***** */
|
||||
/* 此部分为注册至C中的lua通用函数, 实现在lua_plugin_cfunc.c中 */
|
||||
void *lpm_ctx_new_func(struct session *sess, void *plugin_env);
|
||||
void lpm_ctx_free_func(struct session *sess, void *sess_ctx, void *plugin_env);
|
||||
// void lpm_on_session_msg_func(struct session *sess, int topic_id, const void *msg, void *sess_ctx, void *plugin_env);
|
||||
|
||||
/* ***** ***** ***** ***** ***** ***** */
|
||||
/* 此部分主要为插件管理及配置管理相关功能, 实现在lua_plugin_manage.c中 */
|
||||
@@ -241,7 +240,7 @@ struct lua_script
|
||||
int script_instance_init_byname(struct lua_script *script, lua_State *state, const char *filepath, const char *funcname);
|
||||
int script_instance_init_byrefid(struct lua_script *script, lua_State *state, int ref_id);
|
||||
void script_instance_clean(struct lua_script *script);
|
||||
int script_execute(struct lua_script *script, int pcount, struct lua_cdata * param, int rmaxcount, struct lua_cdata * rvalue);
|
||||
int script_execute(struct lua_script *script, int pcount, struct lua_cdata *param, int rmaxcount, struct lua_cdata *rvalue);
|
||||
|
||||
/* 每一个插件的函数信息 */
|
||||
struct lua_session_plugin
|
||||
@@ -312,20 +311,18 @@ struct lua_plugin_manage_schema
|
||||
struct stellar *lua_plugin_schema_st;
|
||||
int lua_config_specific_count;
|
||||
UT_array *lua_config_specific_array;
|
||||
int lua_plugin_thread_count;
|
||||
UT_array *lua_plugin_thread_array;
|
||||
int lua_plugin_state_count;
|
||||
UT_array *lua_plugin_state_array;
|
||||
};
|
||||
|
||||
/* 防止参数错误, 暂时定一个上限 */
|
||||
#define LUA_PLUGIN_MANAGE_MAX_THREAD_COUNT 10
|
||||
|
||||
int lua_plugin_manage_config_load(struct lua_plugin_manage_schema *schema, const char *config_file_name);
|
||||
int lua_plugin_manage_thread_load(struct lua_plugin_manage_schema *schema, int thread_count);
|
||||
int lua_plugin_manage_state_load(struct lua_plugin_manage_schema *schema, int thread_count);
|
||||
|
||||
/* ***** ***** ***** ***** ***** ***** */
|
||||
/* 此部分为注册至C中的lua通用函数, 实现在lua_plugin_cfunc.c中 */
|
||||
void *lpm_ctx_new_func(struct session *sess, void *plugin_env);
|
||||
void lpm_ctx_free_func(struct session *sess, void *sess_ctx, void *plugin_env);
|
||||
// void lpm_on_session_msg_func(struct session *sess, int topic_id, const void *msg, void *sess_ctx, void *plugin_env);
|
||||
#ifdef LUAPLUGIN_BASIC_UNITTEST
|
||||
void debug_lua_state_stack(lua_State *state, int mod, const char *message);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user