【修改】调整部分结构之间依赖关系,重新梳理接口
This commit is contained in:
@@ -14,14 +14,12 @@ void lua_cfunc_mq_msg_free_cb_func(void *msg, void *msg_free_arg)
|
||||
struct lua_fn_arg_pair *free_arg = (struct lua_fn_arg_pair *)msg_free_arg;
|
||||
struct lua_state *state = lua_fn_arg_pair_get_thread_state(free_arg);
|
||||
|
||||
struct lua_cdata param[2];
|
||||
if (lua_context_check_if_context(msg))
|
||||
lua_cdata_data_set(¶m[0], DATATYPE_CONTEXT, msg, 0);
|
||||
else
|
||||
lua_cdata_data_set(¶m[0], DATATYPE_POINTER, msg, 0);
|
||||
lua_cdata_data_set(¶m[1], DATATYPE_TABLE, NULL, lua_fn_arg_pair_get_arg_ref_id(free_arg));
|
||||
|
||||
lua_state_execute_chunk(state, lua_fn_arg_pair_get_fn_ref_id(free_arg), param, 2, NULL, 0, NULL, 0);
|
||||
struct lua_cdata *param_array = lua_cdata_array_new(2);
|
||||
lua_cdata_data_set(lua_cdata_array_get_index(param_array, 0), DATATYPE_CONTEXT, msg, 0);
|
||||
lua_cdata_data_set(lua_cdata_array_get_index(param_array, 1), DATATYPE_TABLE, NULL, lua_fn_arg_pair_get_arg_ref_id(free_arg));
|
||||
lua_state_execute_chunk(state, lua_fn_arg_pair_get_fn_ref_id(free_arg), param_array, 2, NULL, 0, NULL, 0);
|
||||
lua_cdata_array_free(param_array, 2);
|
||||
lua_context_free((struct lua_context *)msg);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -32,15 +30,16 @@ void lua_cfunc_mq_on_msg_cb_func(int topic_id, void *msg, void *on_msg_arg)
|
||||
struct lua_fn_arg_pair *msg_arg = (struct lua_fn_arg_pair *)on_msg_arg;
|
||||
struct lua_state *state = lua_fn_arg_pair_get_thread_state(msg_arg);
|
||||
|
||||
struct lua_cdata param[3];
|
||||
lua_cdata_data_set(¶m[0], DATATYPE_INT, NULL, topic_id);
|
||||
struct lua_cdata *param_array = lua_cdata_array_new(3);
|
||||
lua_cdata_data_set(lua_cdata_array_get_index(param_array, 0), DATATYPE_INT, NULL, topic_id);
|
||||
if (lua_context_check_if_context(msg))
|
||||
lua_cdata_data_set(¶m[1], DATATYPE_CONTEXT, msg, 0);
|
||||
lua_cdata_data_set(lua_cdata_array_get_index(param_array, 1), DATATYPE_CONTEXT, msg, 0);
|
||||
else
|
||||
lua_cdata_data_set(¶m[1], DATATYPE_POINTER, msg, 0);
|
||||
lua_cdata_data_set(¶m[2], DATATYPE_TABLE, NULL, lua_fn_arg_pair_get_arg_ref_id(msg_arg));
|
||||
lua_cdata_data_set(lua_cdata_array_get_index(param_array, 1), DATATYPE_POINTER, msg, 0);
|
||||
lua_cdata_data_set(lua_cdata_array_get_index(param_array, 2), DATATYPE_TABLE, NULL, lua_fn_arg_pair_get_arg_ref_id(msg_arg));
|
||||
|
||||
lua_state_execute_chunk(state, lua_fn_arg_pair_get_fn_ref_id(msg_arg), param, 3, NULL, 0, NULL, 0);
|
||||
lua_state_execute_chunk(state, lua_fn_arg_pair_get_fn_ref_id(msg_arg), param_array, 3, NULL, 0, NULL, 0);
|
||||
lua_cdata_array_free(param_array, 3);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -51,17 +50,18 @@ void lua_cfunc_mq_on_msg_dispatch_cb_func(int topic_id, void *msg, on_msg_cb_fun
|
||||
struct lua_fn_arg_pair *dis_arg = (struct lua_fn_arg_pair *)dispatch_arg;
|
||||
struct lua_state *state = lua_fn_arg_pair_get_thread_state(dis_arg);
|
||||
|
||||
struct lua_cdata param[4];
|
||||
struct lua_cdata *param_array = lua_cdata_array_new(4);
|
||||
struct lua_context *new_context = lua_context_new(state);
|
||||
lua_cdata_data_set(¶m[0], DATATYPE_INT, NULL, topic_id);
|
||||
lua_cdata_data_set(¶m[1], DATATYPE_CONTEXT, msg, 0);
|
||||
lua_cdata_data_set(¶m[2], DATATYPE_TABLE, 0, lua_fn_arg_pair_get_arg_ref_id(dis_arg));
|
||||
lua_cdata_data_set(¶m[3], DATATYPE_CONTEXT, (void *)new_context, 0);
|
||||
lua_cdata_data_set(lua_cdata_array_get_index(param_array, 0), DATATYPE_INT, NULL, topic_id);
|
||||
lua_cdata_data_set(lua_cdata_array_get_index(param_array, 1), DATATYPE_CONTEXT, msg, 0);
|
||||
lua_cdata_data_set(lua_cdata_array_get_index(param_array, 2), DATATYPE_TABLE, 0, lua_fn_arg_pair_get_arg_ref_id(dis_arg));
|
||||
lua_cdata_data_set(lua_cdata_array_get_index(param_array, 3), DATATYPE_CONTEXT, (void *)new_context, 0);
|
||||
|
||||
lua_state_execute_chunk(state, lua_fn_arg_pair_get_fn_ref_id(dis_arg), param, 4, NULL, 0, NULL, 0);
|
||||
lua_state_execute_chunk(state, lua_fn_arg_pair_get_fn_ref_id(dis_arg), param_array, 4, NULL, 0, NULL, 0);
|
||||
lua_cdata_array_free(param_array, 4);
|
||||
((lua_mq_on_msg_cb_func *)(void *)on_msg_cb)(topic_id, msg, on_msg_cb_arg, (void *)new_context);
|
||||
|
||||
lua_context_free(new_context);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -72,12 +72,13 @@ void lua_cfunc_packet_on_stage_callback(enum packet_stage stage, struct packet *
|
||||
struct lua_fn_arg_pair *on_stage_callback = (struct lua_fn_arg_pair *)args;
|
||||
struct lua_state *state = lua_fn_arg_pair_get_thread_state(on_stage_callback);
|
||||
|
||||
struct lua_cdata param[3];
|
||||
lua_cdata_data_set(¶m[0], DATATYPE_INT, NULL, stage);
|
||||
lua_cdata_data_set(¶m[1], DATATYPE_POINTER, pkt, 0);
|
||||
lua_cdata_data_set(¶m[2], DATATYPE_TABLE, NULL, lua_fn_arg_pair_get_arg_ref_id(on_stage_callback));
|
||||
struct lua_cdata *param_array = lua_cdata_array_new(3);
|
||||
lua_cdata_data_set(lua_cdata_array_get_index(param_array, 0), DATATYPE_INT, NULL, stage);
|
||||
lua_cdata_data_set(lua_cdata_array_get_index(param_array, 1), DATATYPE_POINTER, pkt, 0);
|
||||
lua_cdata_data_set(lua_cdata_array_get_index(param_array, 2), DATATYPE_TABLE, NULL, lua_fn_arg_pair_get_arg_ref_id(on_stage_callback));
|
||||
|
||||
lua_state_execute_chunk(state, lua_fn_arg_pair_get_fn_ref_id(on_stage_callback), param, 3, NULL, 0, NULL, 0);
|
||||
lua_state_execute_chunk(state, lua_fn_arg_pair_get_fn_ref_id(on_stage_callback), param_array, 3, NULL, 0, NULL, 0);
|
||||
lua_cdata_array_free(param_array, 3);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -88,12 +89,13 @@ void lua_cfunc_session_callback(struct session *sess, struct packet *pkt, void *
|
||||
struct lua_fn_arg_pair *sess_callback = (struct lua_fn_arg_pair *)args;
|
||||
struct lua_state *state = lua_fn_arg_pair_get_thread_state(sess_callback);
|
||||
|
||||
struct lua_cdata param[3];
|
||||
lua_cdata_data_set(¶m[0], DATATYPE_POINTER, sess, 0);
|
||||
lua_cdata_data_set(¶m[1], DATATYPE_POINTER, pkt, 0);
|
||||
lua_cdata_data_set(¶m[2], DATATYPE_TABLE, NULL, lua_fn_arg_pair_get_arg_ref_id(sess_callback));
|
||||
struct lua_cdata *param_array = lua_cdata_array_new(3);
|
||||
lua_cdata_data_set(lua_cdata_array_get_index(param_array, 0), DATATYPE_POINTER, sess, 0);
|
||||
lua_cdata_data_set(lua_cdata_array_get_index(param_array, 1), DATATYPE_POINTER, pkt, 0);
|
||||
lua_cdata_data_set(lua_cdata_array_get_index(param_array, 2), DATATYPE_TABLE, NULL, lua_fn_arg_pair_get_arg_ref_id(sess_callback));
|
||||
|
||||
lua_state_execute_chunk(state, lua_fn_arg_pair_get_fn_ref_id(sess_callback), param, 3, NULL, 0, NULL, 0);
|
||||
lua_state_execute_chunk(state, lua_fn_arg_pair_get_fn_ref_id(sess_callback), param_array, 3, NULL, 0, NULL, 0);
|
||||
lua_cdata_array_free(param_array, 3);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -104,12 +106,13 @@ void lua_cfunc_tcp_stream_callback(struct session *sess, const char *tcp_payload
|
||||
struct lua_fn_arg_pair *tcp_stream_callback = (struct lua_fn_arg_pair *)args;
|
||||
struct lua_state *state = lua_fn_arg_pair_get_thread_state(tcp_stream_callback);
|
||||
|
||||
struct lua_cdata param[4];
|
||||
lua_cdata_data_set(¶m[0], DATATYPE_POINTER, sess, 0);
|
||||
lua_cdata_data_set(¶m[1], DATATYPE_BUFF, (void *)tcp_payload, (int)tcp_payload_len);
|
||||
lua_cdata_data_set(¶m[2], DATATYPE_INT, NULL, (int)tcp_payload_len);
|
||||
lua_cdata_data_set(¶m[3], DATATYPE_TABLE, NULL, lua_fn_arg_pair_get_arg_ref_id(tcp_stream_callback));
|
||||
struct lua_cdata *param_array = lua_cdata_array_new(4);
|
||||
lua_cdata_data_set(lua_cdata_array_get_index(param_array, 0), DATATYPE_POINTER, sess, 0);
|
||||
lua_cdata_data_set(lua_cdata_array_get_index(param_array, 1), DATATYPE_BUFF, (void *)tcp_payload, (int)tcp_payload_len);
|
||||
lua_cdata_data_set(lua_cdata_array_get_index(param_array, 2), DATATYPE_INT, NULL, (int)tcp_payload_len);
|
||||
lua_cdata_data_set(lua_cdata_array_get_index(param_array, 3), DATATYPE_TABLE, NULL, lua_fn_arg_pair_get_arg_ref_id(tcp_stream_callback));
|
||||
|
||||
lua_state_execute_chunk(state, lua_fn_arg_pair_get_fn_ref_id(tcp_stream_callback), param, 4, NULL, 0, NULL, 0);
|
||||
lua_state_execute_chunk(state, lua_fn_arg_pair_get_fn_ref_id(tcp_stream_callback), param_array, 4, NULL, 0, NULL, 0);
|
||||
lua_cdata_array_free(param_array, 4);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2,12 +2,6 @@
|
||||
#include "lua_binding_function.h"
|
||||
#include "lua_binding_cfunc.h"
|
||||
|
||||
#include "stellar/mq.h"
|
||||
#include "stellar/module_manager.h"
|
||||
#include "stellar/packet.h"
|
||||
#include "stellar/packet_manager.h"
|
||||
#include "stellar/session.h"
|
||||
#include "stellar/session_manager.h"
|
||||
#include "stellar/utils.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
@@ -20,7 +14,7 @@
|
||||
#define LUA_BINDING_FUNCTION_GET_VALUE_POINTER(func_name, param_type, value_type, value_func) \
|
||||
int func_name(struct lua_state *state) \
|
||||
{ \
|
||||
lua_State *L = (lua_State *)lua_state_get_lua_State(state); \
|
||||
lua_State *L = (lua_State *)(state); \
|
||||
if (lua_gettop(L) != 1) \
|
||||
{ \
|
||||
lua_settop(L, 0); \
|
||||
@@ -36,7 +30,7 @@
|
||||
#define LUA_BINDING_FUNCTION_GET_VALUE_INT(func_name, param_type, value_func) \
|
||||
int func_name(struct lua_state *state) \
|
||||
{ \
|
||||
lua_State *L = (lua_State *)lua_state_get_lua_State(state); \
|
||||
lua_State *L = (lua_State *)(state); \
|
||||
if (lua_gettop(L) != 1) \
|
||||
{ \
|
||||
lua_settop(L, 0); \
|
||||
@@ -49,9 +43,56 @@
|
||||
return 1; \
|
||||
}
|
||||
|
||||
int lua_get_lua_module_manager(struct lua_state *state)
|
||||
{
|
||||
lua_State *L = (lua_State *)(state);
|
||||
lua_settop(L, 0);
|
||||
struct lua_module_manager *lua_mod_mgr = lua_state_get_lua_module_manager(state);
|
||||
lua_pushlightuserdata(L, (void *)lua_mod_mgr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
LUA_BINDING_FUNCTION_GET_VALUE_POINTER(lua_get_stellar_module_manager,
|
||||
struct lua_module_manager,
|
||||
struct stellar_module_manager,
|
||||
lua_module_manager_get_stellar_module_manager)
|
||||
|
||||
LUA_BINDING_FUNCTION_GET_VALUE_POINTER(lua_get_mq_schema,
|
||||
struct lua_module_manager,
|
||||
struct mq_schema,
|
||||
lua_module_manager_get_mq_schema)
|
||||
|
||||
LUA_BINDING_FUNCTION_GET_VALUE_POINTER(lua_get_mq_runtime,
|
||||
struct lua_module_manager,
|
||||
struct mq_runtime,
|
||||
lua_module_manager_get_mq_runtime)
|
||||
|
||||
LUA_BINDING_FUNCTION_GET_VALUE_POINTER(lua_get_logger,
|
||||
struct lua_module_manager,
|
||||
struct logger,
|
||||
lua_module_manager_get_logger)
|
||||
|
||||
LUA_BINDING_FUNCTION_GET_VALUE_POINTER(lua_get_packet_manager,
|
||||
struct lua_module_manager,
|
||||
struct packet_manager,
|
||||
lua_module_manager_get_packet_manager)
|
||||
|
||||
LUA_BINDING_FUNCTION_GET_VALUE_POINTER(lua_get_session_manager,
|
||||
struct lua_module_manager,
|
||||
struct session_manager,
|
||||
lua_module_manager_get_session_manager)
|
||||
|
||||
LUA_BINDING_FUNCTION_GET_VALUE_INT(lua_get_current_thread_id,
|
||||
struct lua_module_manager,
|
||||
lua_module_manager_get_current_thread_id)
|
||||
|
||||
LUA_BINDING_FUNCTION_GET_VALUE_INT(lua_get_max_thread_num,
|
||||
struct lua_module_manager,
|
||||
lua_module_manager_get_max_thread_num)
|
||||
|
||||
int lua_mq_schema_get_topic_id(struct lua_state *state)
|
||||
{
|
||||
lua_State *L = (lua_State *)lua_state_get_lua_State(state);
|
||||
lua_State *L = (lua_State *)(state);
|
||||
if (lua_gettop(L) != 2 || lua_type(L, -1) != LUA_TSTRING || lua_type(L, -2) != LUA_TLIGHTUSERDATA)
|
||||
{
|
||||
lua_settop(L, 0);
|
||||
@@ -73,7 +114,7 @@ int lua_mq_schema_get_topic_id(struct lua_state *state)
|
||||
|
||||
int lua_mq_schema_create_topic(struct lua_state *state)
|
||||
{
|
||||
lua_State *L = (lua_State *)lua_state_get_lua_State(state);
|
||||
lua_State *L = (lua_State *)(state);
|
||||
if (lua_gettop(L) != 6 || lua_type(L, -5) != LUA_TSTRING || lua_type(L, -6) != LUA_TLIGHTUSERDATA)
|
||||
{
|
||||
lua_settop(L, 0);
|
||||
@@ -269,34 +310,6 @@ int lua_mq_runtime_publish_message(struct lua_state *state)
|
||||
return 1;
|
||||
}
|
||||
|
||||
LUA_BINDING_FUNCTION_GET_VALUE_POINTER(lua_stellar_get_stellar_module_manager,
|
||||
struct lua_module_manager,
|
||||
struct stellar_module_manager,
|
||||
lua_module_manager_get_stellar_module_manager)
|
||||
|
||||
LUA_BINDING_FUNCTION_GET_VALUE_INT(lua_stellar_get_thread_id,
|
||||
struct stellar_module_manager,
|
||||
stellar_module_manager_get_thread_id)
|
||||
|
||||
LUA_BINDING_FUNCTION_GET_VALUE_INT(lua_stellar_get_max_thread_num,
|
||||
struct stellar_module_manager,
|
||||
stellar_module_manager_get_max_thread_num)
|
||||
|
||||
LUA_BINDING_FUNCTION_GET_VALUE_POINTER(lua_stellar_get_mq_runtime,
|
||||
struct stellar_module_manager,
|
||||
struct mq_runtime,
|
||||
stellar_module_manager_get_mq_runtime)
|
||||
|
||||
LUA_BINDING_FUNCTION_GET_VALUE_POINTER(lua_stellar_get_mq_schema,
|
||||
struct stellar_module_manager,
|
||||
struct mq_schema,
|
||||
stellar_module_manager_get_mq_schema)
|
||||
|
||||
LUA_BINDING_FUNCTION_GET_VALUE_POINTER(lua_stellar_get_logger,
|
||||
struct stellar_module_manager,
|
||||
struct logger,
|
||||
stellar_module_manager_get_logger)
|
||||
|
||||
LUA_BINDING_FUNCTION_GET_VALUE_INT(lua_packet_get_direction,
|
||||
const struct packet,
|
||||
packet_get_direction)
|
||||
@@ -362,7 +375,7 @@ enum sess_mgr_sub_type
|
||||
|
||||
static int lua_session_manager_subscribe(struct lua_state *state, enum sess_mgr_sub_type type)
|
||||
{
|
||||
lua_State *L = (lua_State *)state;
|
||||
lua_State *L = (lua_State *)(state);
|
||||
if (lua_gettop(L) != 3 || lua_type(L, -2) != LUA_TFUNCTION || lua_type(L, -3) != LUA_TLIGHTUSERDATA)
|
||||
{
|
||||
lua_settop(L, 0);
|
||||
@@ -425,7 +438,7 @@ int lua_session_manager_subscribe_control_packet(struct lua_state *state)
|
||||
|
||||
int lua_session_manager_subscribe_tcp_stream(struct lua_state *state)
|
||||
{
|
||||
lua_State *L = (lua_State *)state;
|
||||
lua_State *L = (lua_State *)(state);
|
||||
if (lua_gettop(L) != 3 || lua_type(L, -2) != LUA_TFUNCTION || lua_type(L, -4) != LUA_TLIGHTUSERDATA)
|
||||
{
|
||||
lua_settop(L, 0);
|
||||
|
||||
@@ -7,6 +7,16 @@ extern "C"
|
||||
|
||||
#include "lua_module_manage_internal.h"
|
||||
|
||||
int lua_get_lua_module_manager(struct lua_state *state);
|
||||
int lua_get_stellar_module_manager(struct lua_state *state);
|
||||
int lua_get_mq_schema(struct lua_state *state);
|
||||
int lua_get_mq_runtime(struct lua_state *state);
|
||||
int lua_get_logger(struct lua_state *state);
|
||||
int lua_get_packet_manager(struct lua_state *state);
|
||||
int lua_get_session_manager(struct lua_state *state);
|
||||
int lua_get_current_thread_id(struct lua_state *state);
|
||||
int lua_get_max_thread_num(struct lua_state *state);
|
||||
|
||||
int lua_mq_schema_get_topic_id(struct lua_state *state);
|
||||
int lua_mq_schema_create_topic(struct lua_state *state);
|
||||
int lua_mq_schema_update_topic(struct lua_state *state);
|
||||
@@ -14,13 +24,6 @@ extern "C"
|
||||
int lua_mq_schema_subscribe(struct lua_state *state);
|
||||
int lua_mq_runtime_publish_message(struct lua_state *state);
|
||||
|
||||
int lua_stellar_get_stellar_module_manager(struct lua_state *state);
|
||||
int lua_stellar_get_thread_id(struct lua_state *state);
|
||||
int lua_stellar_get_max_thread_num(struct lua_state *state);
|
||||
int lua_stellar_get_mq_runtime(struct lua_state *state);
|
||||
int lua_stellar_get_mq_schema(struct lua_state *state);
|
||||
int lua_stellar_get_logger(struct lua_state *state);
|
||||
|
||||
int lua_packet_get_direction(struct lua_state *state);
|
||||
int lua_packet_get_payload(struct lua_state *state);
|
||||
int lua_packet_get_payload_len(struct lua_state *state);
|
||||
|
||||
@@ -3,19 +3,26 @@
|
||||
|
||||
#include "stellar/utils.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define MQ_SCHEMA_SPACE_NAME "mq_schema"
|
||||
#define MQ_RUNTIME_SPACE_NAME "mq_runtime"
|
||||
#define MODULE_MANAGER_SPACE_NAME "module_manager"
|
||||
#define PACKET_SPACE_NAME "packet"
|
||||
#define PACKET_MANAGER_SPACE_NAME "packet_manager"
|
||||
#define SESSION_SPACE_NAME "session"
|
||||
#define SESSION_MANAGER_SPACE_NAME "session_manager"
|
||||
#define GLOBAL_BASIC_SPACE_NAME "lua_module_manager_space"
|
||||
#define MQ_SCHEMA_SPACE_NAME "mq_schema_space"
|
||||
#define MQ_RUNTIME_SPACE_NAME "mq_runtime_space"
|
||||
#define MODULE_MANAGER_SPACE_NAME "stellar_module_manager_space"
|
||||
#define PACKET_SPACE_NAME "packet_space"
|
||||
#define PACKET_MANAGER_SPACE_NAME "packet_manager_space"
|
||||
#define SESSION_SPACE_NAME "session_space"
|
||||
#define SESSION_MANAGER_SPACE_NAME "session_manager_space"
|
||||
|
||||
struct lua_state_cbind_func_spec lua_bind_function[] = {
|
||||
{lua_get_lua_module_manager, GLOBAL_BASIC_SPACE_NAME, "get_lua_module_manager"},
|
||||
{lua_get_stellar_module_manager, GLOBAL_BASIC_SPACE_NAME, "get_stellar_module_manager"},
|
||||
{lua_get_mq_schema, GLOBAL_BASIC_SPACE_NAME, "get_mq_schema"},
|
||||
{lua_get_mq_runtime, GLOBAL_BASIC_SPACE_NAME, "get_mq_runtime"},
|
||||
{lua_get_logger, GLOBAL_BASIC_SPACE_NAME, "get_logger"},
|
||||
{lua_get_packet_manager, GLOBAL_BASIC_SPACE_NAME, "get_pacekt_manager"},
|
||||
{lua_get_session_manager, GLOBAL_BASIC_SPACE_NAME, "get_session_manager"},
|
||||
{lua_get_current_thread_id, GLOBAL_BASIC_SPACE_NAME, "get_current_thread_id"},
|
||||
{lua_get_max_thread_num, GLOBAL_BASIC_SPACE_NAME, "get_max_thread_num"},
|
||||
|
||||
{lua_mq_schema_get_topic_id, MQ_SCHEMA_SPACE_NAME, "get_topic_id"},
|
||||
{lua_mq_schema_create_topic, MQ_SCHEMA_SPACE_NAME, "create_topic"},
|
||||
{lua_mq_schema_update_topic, MQ_SCHEMA_SPACE_NAME, "update_topic"},
|
||||
@@ -23,12 +30,6 @@ struct lua_state_cbind_func_spec lua_bind_function[] = {
|
||||
{lua_mq_schema_subscribe, MQ_SCHEMA_SPACE_NAME, "subcribe"},
|
||||
{lua_mq_runtime_publish_message, MQ_RUNTIME_SPACE_NAME, "publish_message"},
|
||||
|
||||
{lua_stellar_get_thread_id, MODULE_MANAGER_SPACE_NAME, "get_thread_id"},
|
||||
{lua_stellar_get_max_thread_num, MODULE_MANAGER_SPACE_NAME, "get_max_thread_num"},
|
||||
{lua_stellar_get_mq_runtime, MODULE_MANAGER_SPACE_NAME, "get_mq_runtime"},
|
||||
{lua_stellar_get_mq_schema, MODULE_MANAGER_SPACE_NAME, "get_mq_schema"},
|
||||
{lua_stellar_get_logger, MODULE_MANAGER_SPACE_NAME, "get_logger"},
|
||||
|
||||
{lua_packet_get_direction, PACKET_SPACE_NAME, "get_direction"},
|
||||
{lua_packet_get_payload, PACKET_SPACE_NAME, "get_payload"},
|
||||
{lua_packet_get_payload_len, PACKET_SPACE_NAME, "get_payload_len"},
|
||||
@@ -65,16 +66,16 @@ struct stellar_module *lua_module_manager_on_init(struct stellar_module_manager
|
||||
lua_bind_data,
|
||||
sizeof(lua_bind_data) / sizeof(struct lua_state_cbind_data_spec)))
|
||||
goto err;
|
||||
|
||||
|
||||
if (lua_module_manager_load_config(new_lua_mod_mgr, LUA_MODULE_MANAGE_CONF_PATH))
|
||||
goto err;
|
||||
|
||||
if (lua_module_manager_call_init(new_lua_mod_mgr))
|
||||
goto err;
|
||||
|
||||
|
||||
if (lua_module_manager_duplicate_state(new_lua_mod_mgr))
|
||||
goto err;
|
||||
|
||||
|
||||
struct stellar_module *module = stellar_module_new(LUA_MODULE_MANAGE_MODULE_NAME, (void *)new_lua_mod_mgr);
|
||||
return module;
|
||||
err:
|
||||
@@ -84,8 +85,11 @@ err:
|
||||
|
||||
void lua_module_manager_on_exit(struct stellar_module_manager *mod_mgr __unused, struct stellar_module *mod)
|
||||
{
|
||||
struct lua_module_manager *lua_mod_mgr = (struct lua_module_manager *)stellar_module_get_ctx(mod);
|
||||
lua_module_manager_free(lua_mod_mgr);
|
||||
stellar_module_free(mod);
|
||||
if (mod)
|
||||
{
|
||||
struct lua_module_manager *lua_mod_mgr = (struct lua_module_manager *)stellar_module_get_ctx(mod);
|
||||
lua_module_manager_free(lua_mod_mgr);
|
||||
stellar_module_free(mod);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -25,7 +25,7 @@ struct lua_context *lua_context_new(struct lua_state *state)
|
||||
{
|
||||
if (!state)
|
||||
return NULL;
|
||||
lua_State *L = (lua_State *)lua_state_get_lua_State(state);
|
||||
lua_State *L = (lua_State *)(state);
|
||||
|
||||
lua_newtable(L);
|
||||
int ref_id = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
@@ -50,7 +50,7 @@ void lua_context_free(struct lua_context *context)
|
||||
{
|
||||
if (!context)
|
||||
return;
|
||||
luaL_unref((lua_State *)lua_state_get_lua_State(context->state), LUA_REGISTRYINDEX, context->lua_context_ref_id);
|
||||
luaL_unref((lua_State *)(context->state), LUA_REGISTRYINDEX, context->lua_context_ref_id);
|
||||
FREE(context);
|
||||
return;
|
||||
}
|
||||
@@ -58,7 +58,7 @@ void lua_context_free(struct lua_context *context)
|
||||
void lua_context_push_stack(struct lua_context *context)
|
||||
{
|
||||
if (context && context->lua_context_ref_id)
|
||||
lua_rawgeti((lua_State *)lua_state_get_lua_State(context->state), LUA_REGISTRYINDEX, context->lua_context_ref_id);
|
||||
lua_rawgeti((lua_State *)(context->state), LUA_REGISTRYINDEX, context->lua_context_ref_id);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -88,6 +88,26 @@ struct lua_ctable
|
||||
struct lua_cnode **node_data;
|
||||
};
|
||||
|
||||
struct lua_cdata
|
||||
{
|
||||
enum LUA_DATATYPE type;
|
||||
size_t data_len; /* 只有在类型为buff或function时使用此标识 */
|
||||
union
|
||||
{
|
||||
int bool;
|
||||
int integer;
|
||||
double number;
|
||||
char *string;
|
||||
|
||||
char *buff;
|
||||
int table;
|
||||
void *pointer;
|
||||
struct lua_context *context;
|
||||
void *function;
|
||||
struct lua_ctable *ctable;
|
||||
};
|
||||
};
|
||||
|
||||
static struct lua_ctable *lua_ctable_new(void);
|
||||
static void lua_ctable_free(struct lua_ctable *ctable);
|
||||
static int lua_ctable_push_stack(struct lua_state *state, struct lua_ctable *ctable);
|
||||
@@ -104,9 +124,9 @@ struct lua_cdata *lua_cdata_new(void)
|
||||
return new_data;
|
||||
}
|
||||
|
||||
static void lua_cdata_inner_data_free(struct lua_cdata *cdata)
|
||||
static void lua_cdata_inner_data_clean(struct lua_cdata *cdata)
|
||||
{
|
||||
cdata->type = 0;
|
||||
cdata->type = DATATYPE_BEGIN;
|
||||
cdata->data_len = 0;
|
||||
switch (cdata->type)
|
||||
{
|
||||
@@ -132,16 +152,42 @@ void lua_cdata_free(struct lua_cdata *cdata)
|
||||
{
|
||||
if (!cdata)
|
||||
return;
|
||||
lua_cdata_inner_data_free(cdata);
|
||||
lua_cdata_inner_data_clean(cdata);
|
||||
FREE(cdata);
|
||||
return;
|
||||
}
|
||||
|
||||
struct lua_cdata *lua_cdata_array_new(size_t cdata_num)
|
||||
{
|
||||
if (cdata_num == 0)
|
||||
return NULL;
|
||||
struct lua_cdata *new_cdata = CALLOC(struct lua_cdata, cdata_num);
|
||||
memset(new_cdata, 0, sizeof(struct lua_cdata) * cdata_num);
|
||||
return new_cdata;
|
||||
}
|
||||
|
||||
void lua_cdata_array_free(struct lua_cdata *cdata_array, size_t data_num)
|
||||
{
|
||||
if (!cdata_array || data_num == 0)
|
||||
return;
|
||||
for (size_t data_index = 0; data_index < data_num; ++data_index)
|
||||
{
|
||||
lua_cdata_inner_data_clean(&cdata_array[data_index]);
|
||||
}
|
||||
FREE(cdata_array);
|
||||
return;
|
||||
}
|
||||
|
||||
struct lua_cdata *lua_cdata_array_get_index(struct lua_cdata *data_array, size_t index)
|
||||
{
|
||||
return (struct lua_cdata *)(data_array + index);
|
||||
}
|
||||
|
||||
int lua_cdata_data_set(struct lua_cdata *cdata, enum LUA_DATATYPE type, void *value_p, int value_i)
|
||||
{
|
||||
if (!cdata)
|
||||
return PARAM_ERR;
|
||||
lua_cdata_inner_data_free(cdata);
|
||||
lua_cdata_inner_data_clean(cdata);
|
||||
switch (type)
|
||||
{
|
||||
case DATATYPE_NIL:
|
||||
@@ -156,10 +202,15 @@ int lua_cdata_data_set(struct lua_cdata *cdata, enum LUA_DATATYPE type, void *va
|
||||
cdata->number = *(double *)value_p;
|
||||
break;
|
||||
case DATATYPE_STRING:
|
||||
if (!value_p || value_i <= 0)
|
||||
return CDATA_SET_VALUE_NULL_POINTER;
|
||||
cdata->string = CALLOC(char, value_i);
|
||||
memcpy(cdata->string, value_p, (size_t)value_i);
|
||||
cdata->data_len = (size_t)value_i;
|
||||
break;
|
||||
case DATATYPE_BUFF:
|
||||
if (!value_p || value_i <= 0)
|
||||
return CDATA_SET_VALUE_NULL_POINTER;
|
||||
cdata->buff = CALLOC(char, value_i);
|
||||
memcpy(cdata->buff, value_p, (size_t)value_i);
|
||||
cdata->data_len = (size_t)value_i;
|
||||
@@ -184,7 +235,7 @@ int lua_cdata_push_stack(struct lua_state *state, struct lua_cdata *cdata)
|
||||
{
|
||||
if (!state || !cdata)
|
||||
return PARAM_ERR;
|
||||
lua_State *L = (lua_State *)lua_state_get_lua_State(state);
|
||||
lua_State *L = (lua_State *)(state);
|
||||
|
||||
switch (cdata->type)
|
||||
{
|
||||
@@ -232,9 +283,9 @@ int lua_cdata_pop_stack(struct lua_state *state, struct lua_cdata *cdata)
|
||||
{
|
||||
if (!state || !cdata)
|
||||
return PARAM_ERR;
|
||||
lua_State *L = (lua_State *)lua_state_get_lua_State(state);
|
||||
lua_State *L = (lua_State *)(state);
|
||||
|
||||
lua_cdata_inner_data_free(cdata);
|
||||
lua_cdata_inner_data_clean(cdata);
|
||||
switch (lua_type(L, -1))
|
||||
{
|
||||
case LUA_TNIL:
|
||||
@@ -313,7 +364,7 @@ static int lua_ctable_push_stack(struct lua_state *state, struct lua_ctable *cta
|
||||
{
|
||||
if (!state || !ctable)
|
||||
return PARAM_ERR;
|
||||
lua_State *L = (lua_State *)lua_state_get_lua_State(state);
|
||||
lua_State *L = (lua_State *)(state);
|
||||
lua_newtable(L);
|
||||
int push_ret = 0;
|
||||
for (unsigned array_index = 0; array_index < ctable->array_size; array_index++)
|
||||
@@ -349,7 +400,7 @@ static int lua_ctable_pop_stack(struct lua_state *state, struct lua_ctable *ctab
|
||||
{
|
||||
if (!state || !ctable)
|
||||
return PARAM_ERR;
|
||||
lua_State *L = (lua_State *)lua_state_get_lua_State(state);
|
||||
lua_State *L = (lua_State *)(state);
|
||||
|
||||
/* 获取table长度 */
|
||||
ctable->array_size = (size_t)lua_rawlen(L, -1);
|
||||
@@ -445,6 +496,59 @@ static const char *lua_cdata_function_writer(lua_State *state __unused, void *ud
|
||||
return (const char *)data->function;
|
||||
}
|
||||
|
||||
/* ***** ***** ***** ***** ***** ***** */
|
||||
/* lua fn arg pair */
|
||||
/* ***** ***** ***** ***** ***** ***** */
|
||||
struct lua_fn_arg_pair
|
||||
{
|
||||
struct lua_fn_arg_pair *next;
|
||||
struct lua_module_manager *lua_mod_mgr;
|
||||
int lua_fn_ref_id;
|
||||
int lua_arg_ref_id;
|
||||
};
|
||||
|
||||
struct lua_fn_arg_pair *lua_fn_arg_pair_new(struct lua_module_manager *lua_mod_mgr, int fn_ref_id, int arg_ref_id)
|
||||
{
|
||||
struct lua_fn_arg_pair *new_pair = CALLOC(struct lua_fn_arg_pair, 1);
|
||||
new_pair->lua_mod_mgr = lua_mod_mgr;
|
||||
new_pair->lua_fn_ref_id = fn_ref_id;
|
||||
new_pair->lua_arg_ref_id = arg_ref_id;
|
||||
return new_pair;
|
||||
}
|
||||
|
||||
void lua_fn_arg_pair_free(struct lua_fn_arg_pair *pair)
|
||||
{
|
||||
if (pair)
|
||||
FREE(pair);
|
||||
return;
|
||||
}
|
||||
|
||||
void lua_fn_arg_pair_insert(struct lua_fn_arg_pair *pair)
|
||||
{
|
||||
return lua_module_manger_pair_list_insert(pair->lua_mod_mgr, pair);
|
||||
}
|
||||
|
||||
int lua_fn_arg_pair_get_fn_ref_id(struct lua_fn_arg_pair *pair)
|
||||
{
|
||||
if (pair)
|
||||
return pair->lua_fn_ref_id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lua_fn_arg_pair_get_arg_ref_id(struct lua_fn_arg_pair *pair)
|
||||
{
|
||||
if (pair)
|
||||
return pair->lua_arg_ref_id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct lua_module_manager *lua_fn_arg_pair_get_lua_mod_mgr(struct lua_fn_arg_pair *pair)
|
||||
{
|
||||
if (pair)
|
||||
return pair->lua_mod_mgr;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* ***** ***** ***** ***** ***** ***** */
|
||||
/* lua state */
|
||||
/* ***** ***** ***** ***** ***** ***** */
|
||||
@@ -477,31 +581,17 @@ struct lua_state *lua_state_new(struct lua_module_manager *lua_mod_mgr)
|
||||
|
||||
void lua_state_free(struct lua_state *state)
|
||||
{
|
||||
lua_State *L = (lua_State *)state;
|
||||
lua_close(L);
|
||||
if (!state)
|
||||
return;
|
||||
lua_close((lua_State *)state);
|
||||
return;
|
||||
}
|
||||
|
||||
struct lua_module_manager *lua_state_get_lua_module_manager(struct lua_state *state)
|
||||
{
|
||||
lua_State *L = (lua_State *)lua_state_get_lua_State(state);
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_GLOBAL_INFO_REF_ID);
|
||||
lua_getfield(L, -1, LUA_GLOBAL_INFO_MANAGE_POINTER);
|
||||
struct lua_module_manager *lua_mod_mgr = (struct lua_module_manager *)lua_topointer(L, -1);
|
||||
lua_settop(L, 0);
|
||||
return lua_mod_mgr;
|
||||
}
|
||||
|
||||
void *lua_state_get_lua_State(struct lua_state *state)
|
||||
{
|
||||
return (void *)state;
|
||||
}
|
||||
|
||||
int lua_state_cbinding_function(struct lua_state *state, struct lua_state_cbind_func_spec *bind_func_array, size_t bind_func_num)
|
||||
{
|
||||
if (!state || !bind_func_array)
|
||||
return PARAM_ERR;
|
||||
lua_State *L = (lua_State *)lua_state_get_lua_State(state);
|
||||
lua_State *L = (lua_State *)(state);
|
||||
for (size_t index = 0; index < bind_func_num; ++index)
|
||||
{
|
||||
if (bind_func_array[index].func && bind_func_array[index].func_name)
|
||||
@@ -557,7 +647,7 @@ int lua_state_cbinding_data(struct lua_state *state, struct lua_state_cbind_data
|
||||
{
|
||||
if (!state || !bind_data_array)
|
||||
return PARAM_ERR;
|
||||
lua_State *L = (lua_State *)lua_state_get_lua_State(state);
|
||||
lua_State *L = (lua_State *)(state);
|
||||
for (size_t index = 0; index < bind_data_num; ++index)
|
||||
{
|
||||
if (bind_data_array[index].data_value && bind_data_array[index].data_name)
|
||||
@@ -655,8 +745,8 @@ int lua_state_copy_ref_value(struct lua_state *to, struct lua_state *from)
|
||||
{
|
||||
if (!to || !from)
|
||||
return PARAM_ERR;
|
||||
lua_State *from_L = (lua_State *)lua_state_get_lua_State(from);
|
||||
lua_State *to_L = (lua_State *)lua_state_get_lua_State(to);
|
||||
lua_State *from_L = (lua_State *)(from);
|
||||
lua_State *to_L = (lua_State *)(to);
|
||||
|
||||
lua_newtable(from_L);
|
||||
int lua_ref_max_id = luaL_ref(from_L, LUA_REGISTRYINDEX);
|
||||
@@ -752,59 +842,19 @@ int lua_state_execute_chunk(
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
struct lua_module_manager *lua_state_get_lua_module_manager(struct lua_state *state)
|
||||
{
|
||||
lua_State *L = (lua_State *)(state);
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_GLOBAL_INFO_REF_ID);
|
||||
lua_getfield(L, -1, LUA_GLOBAL_INFO_MANAGE_POINTER);
|
||||
struct lua_module_manager *lua_mod_mgr = (struct lua_module_manager *)lua_topointer(L, -1);
|
||||
lua_settop(L, 0);
|
||||
return lua_mod_mgr;
|
||||
}
|
||||
|
||||
/* ***** ***** ***** ***** ***** ***** */
|
||||
/* lua module manager */
|
||||
/* ***** ***** ***** ***** ***** ***** */
|
||||
struct lua_fn_arg_pair
|
||||
{
|
||||
struct lua_fn_arg_pair *next;
|
||||
struct lua_module_manager *lua_mod_mgr;
|
||||
int lua_fn_ref_id;
|
||||
int lua_arg_ref_id;
|
||||
};
|
||||
|
||||
struct lua_fn_arg_pair *lua_fn_arg_pair_new(struct lua_module_manager *lua_mod_mgr, int fn_ref_id, int arg_ref_id)
|
||||
{
|
||||
struct lua_fn_arg_pair *new_pair = CALLOC(struct lua_fn_arg_pair, 1);
|
||||
new_pair->lua_mod_mgr = lua_mod_mgr;
|
||||
new_pair->lua_fn_ref_id = fn_ref_id;
|
||||
new_pair->lua_arg_ref_id = arg_ref_id;
|
||||
return new_pair;
|
||||
}
|
||||
|
||||
void lua_fn_arg_pair_free(struct lua_fn_arg_pair *pair)
|
||||
{
|
||||
if (pair)
|
||||
FREE(pair);
|
||||
return;
|
||||
}
|
||||
|
||||
void lua_fn_arg_pair_insert(struct lua_fn_arg_pair *pair)
|
||||
{
|
||||
lua_module_manger_pair_list_insert(pair->lua_mod_mgr, pair);
|
||||
return;
|
||||
}
|
||||
|
||||
int lua_fn_arg_pair_get_fn_ref_id(struct lua_fn_arg_pair *pair)
|
||||
{
|
||||
if (pair)
|
||||
return pair->lua_fn_ref_id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lua_fn_arg_pair_get_arg_ref_id(struct lua_fn_arg_pair *pair)
|
||||
{
|
||||
if (pair)
|
||||
return pair->lua_arg_ref_id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct lua_module_manager *lua_fn_arg_pair_get_lua_mod_mgr(struct lua_fn_arg_pair *pair)
|
||||
{
|
||||
if (pair)
|
||||
return pair->lua_mod_mgr;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct lua_load_script
|
||||
{
|
||||
@@ -849,22 +899,6 @@ struct lua_module_manager *lua_module_manager_new(struct stellar_module_manager
|
||||
return new_lua_mod_mgr;
|
||||
}
|
||||
|
||||
/*
|
||||
static inline void lua_fn_arg_pair_list_free(struct lua_fn_arg_pair *pair)
|
||||
{
|
||||
struct lua_fn_arg_pair *free_pair = NULL;
|
||||
struct lua_fn_arg_pair *next_pair = NULL;
|
||||
free_pair = pair;
|
||||
while (free_pair)
|
||||
{
|
||||
next_pair = free_pair->next;
|
||||
FREE(free_pair);
|
||||
free_pair = next_pair;
|
||||
}
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
void lua_module_manager_free(struct lua_module_manager *lua_mod_mgr)
|
||||
{
|
||||
if (!lua_mod_mgr)
|
||||
@@ -893,18 +927,9 @@ void lua_module_manager_free(struct lua_module_manager *lua_mod_mgr)
|
||||
while (free_pair)
|
||||
{
|
||||
next_pair = free_pair->next;
|
||||
FREE(free_pair);
|
||||
lua_fn_arg_pair_free(free_pair);
|
||||
free_pair = next_pair;
|
||||
}
|
||||
/*
|
||||
lua_fn_arg_pair_list_free(lua_mod_mgr->mq_msg_free_list);
|
||||
lua_fn_arg_pair_list_free(lua_mod_mgr->mq_on_msg_list);
|
||||
lua_fn_arg_pair_list_free(lua_mod_mgr->on_packet_stage_list);
|
||||
lua_fn_arg_pair_list_free(lua_mod_mgr->on_session_tcp_list);
|
||||
lua_fn_arg_pair_list_free(lua_mod_mgr->on_session_udp_list);
|
||||
lua_fn_arg_pair_list_free(lua_mod_mgr->on_session_control_packet_list);
|
||||
lua_fn_arg_pair_list_free(lua_mod_mgr->on_tcp_stream_list);
|
||||
*/
|
||||
|
||||
FREE(lua_mod_mgr);
|
||||
return;
|
||||
@@ -998,7 +1023,7 @@ int lua_module_manager_call_init(struct lua_module_manager *lua_mod_mgr)
|
||||
if (lua_mod_mgr->state_num == 0)
|
||||
return SUCCESS;
|
||||
|
||||
lua_State *L = (lua_State *)lua_state_get_lua_State(lua_mod_mgr->state_array[0]);
|
||||
lua_State *L = (lua_State *)(lua_mod_mgr->state_array[0]);
|
||||
int execute_ret = SUCCESS;
|
||||
for (size_t script_index = 0; script_index < lua_mod_mgr->load_script_num; ++script_index)
|
||||
{
|
||||
@@ -1069,17 +1094,74 @@ int lua_module_manager_call_exit(struct lua_module_manager *lua_mod_mgr)
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
struct lua_state *lua_module_manager_get_current_thread_state(struct lua_module_manager *lua_mod_mgr)
|
||||
{
|
||||
if (!lua_mod_mgr)
|
||||
return NULL;
|
||||
int thread_id = stellar_module_manager_get_thread_id(lua_mod_mgr->mod_mgr);
|
||||
return lua_mod_mgr->state_array[thread_id];
|
||||
}
|
||||
|
||||
struct stellar_module_manager *lua_module_manager_get_stellar_module_manager(struct lua_module_manager *lua_mod_mgr)
|
||||
{
|
||||
if (lua_mod_mgr)
|
||||
return lua_mod_mgr->mod_mgr;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
struct mq_schema *lua_module_manager_get_mq_schema(struct lua_module_manager *lua_mod_mgr)
|
||||
{
|
||||
if (lua_mod_mgr)
|
||||
return stellar_module_manager_get_mq_schema(lua_mod_mgr->mod_mgr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mq_runtime *lua_module_manager_get_mq_runtime(struct lua_module_manager *lua_mod_mgr)
|
||||
{
|
||||
if (lua_mod_mgr)
|
||||
return stellar_module_manager_get_mq_runtime(lua_mod_mgr->mod_mgr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct logger *lua_module_manager_get_logger(struct lua_module_manager *lua_mod_mgr)
|
||||
{
|
||||
if (lua_mod_mgr)
|
||||
return stellar_module_manager_get_logger(lua_mod_mgr->mod_mgr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct packet_manager *lua_module_manager_get_packet_manager(struct lua_module_manager *lua_mod_mgr)
|
||||
{
|
||||
if (lua_mod_mgr)
|
||||
{
|
||||
struct stellar_module *pkt_module = stellar_module_manager_get_module(lua_mod_mgr->mod_mgr, PACKET_MANAGER_MODULE_NAME);
|
||||
return (struct packet_manager *)stellar_module_get_ctx(pkt_module);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct session_manager *lua_module_manager_get_session_manager(struct lua_module_manager *lua_mod_mgr)
|
||||
{
|
||||
if (lua_mod_mgr)
|
||||
{
|
||||
struct stellar_module *sess_module = stellar_module_manager_get_module(lua_mod_mgr->mod_mgr, SESSION_MANAGER_MODULE_NAME);
|
||||
return (struct session_manager *)stellar_module_get_ctx(sess_module);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int lua_module_manager_get_current_thread_id(struct lua_module_manager *lua_mod_mgr)
|
||||
{
|
||||
if (lua_mod_mgr)
|
||||
return stellar_module_manager_get_thread_id(lua_mod_mgr->mod_mgr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct lua_state *lua_module_manager_get_current_thread_state(struct lua_module_manager *lua_mod_mgr)
|
||||
{
|
||||
if (!lua_mod_mgr)
|
||||
return NULL;
|
||||
int thread_id = stellar_module_manager_get_thread_id(lua_mod_mgr->mod_mgr);
|
||||
if (thread_id < 0)
|
||||
return NULL;
|
||||
return lua_mod_mgr->state_array[thread_id];
|
||||
}
|
||||
|
||||
int lua_module_manager_get_max_thread_num(struct lua_module_manager *lua_mod_mgr)
|
||||
{
|
||||
if (lua_mod_mgr)
|
||||
return stellar_module_manager_get_max_thread_num(lua_mod_mgr->mod_mgr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -7,12 +7,19 @@ extern "C"
|
||||
|
||||
#include <stddef.h>
|
||||
#include "lua_module_manage.h"
|
||||
#include "stellar/mq.h"
|
||||
#include "stellar/module_manager.h"
|
||||
#include "stellar/packet.h"
|
||||
#include "stellar/packet_manager.h"
|
||||
#include "stellar/session.h"
|
||||
#include "stellar/session_manager.h"
|
||||
|
||||
enum LUA_MODULE_ERR_CODE
|
||||
{
|
||||
/* 函数与全局变量操作错误码 */
|
||||
CDATA_ERR = -300,
|
||||
CDATA_SET_VALUE_TYPE_UNSUPPORT, /* 使用了未识别的数据类型 */
|
||||
CDATA_SET_VALUE_NULL_POINTER,
|
||||
CDATA_PUSH_STACK_TYPE_UNKNOWN, /* 入栈数据无法识别数据类型 */
|
||||
CDATA_POP_STACK_TYPE_UNSUPPORT, /* 出栈数据类型不支持出栈 */
|
||||
/* 状态机基础操作中错误码 */
|
||||
@@ -30,18 +37,13 @@ extern "C"
|
||||
STATE_CHUNK_RUNNING_ERR, /* CHUNK在调用pcall执行过程中运行错误 */
|
||||
/* lua module manager错误码 */
|
||||
LUA_MOD_MGR_ERR = -100,
|
||||
LMM_STATE_THREAD_NUM_ERR,
|
||||
LMM_STATE_CREATE_ERR,
|
||||
LMM_LOAD_CONFIG_FILE_NOT_EXIST,
|
||||
LMM_LOAD_CONFIG_FILE_OPEN_ERR,
|
||||
LMM_LOAD_CONFIG_FILE_TOML_PARSE_ERR,
|
||||
LMM_LOAD_SCRIPT_FILE_OPEN_ERR,
|
||||
LMM_LOAD_SCRIPT_FUNC_TYPE_ERR,
|
||||
|
||||
LMM_CALL_INIT_FILE_OPEN_ERR,
|
||||
LMM_CALL_INIT_FUNCTION_TYPE_ERR,
|
||||
LMM_CALL_EXIT_FILE_OPEN_ERR,
|
||||
LMM_CALL_EXIT_FUNCTION_TYPE_ERR,
|
||||
LMM_STATE_THREAD_NUM_ERR, /* 获取最大线程数量时结果为负数 */
|
||||
LMM_STATE_CREATE_ERR, /* lua_State创建失败 */
|
||||
LMM_LOAD_CONFIG_FILE_NOT_EXIST, /* 读取配置时配置文件不存在 */
|
||||
LMM_LOAD_CONFIG_FILE_OPEN_ERR, /* 配置文件无法打开 */
|
||||
LMM_LOAD_CONFIG_FILE_TOML_PARSE_ERR, /* 配置文件通过toml解析失败 */
|
||||
LMM_LOAD_SCRIPT_FILE_OPEN_ERR, /* 加载配置过程中lua无法打开文件 */
|
||||
LMM_LOAD_SCRIPT_FUNC_TYPE_ERR, /* lua获取得到的变量类型不是函数,无法完成初始化 */
|
||||
/* 通用返回值 */
|
||||
PARAM_ERR = -1, /* 传入参数错误, 可能是指针为空或类型不符合 */
|
||||
SUCCESS = 0, /* 运行成功 */
|
||||
@@ -77,32 +79,25 @@ extern "C"
|
||||
DATATYPE_END
|
||||
};
|
||||
|
||||
struct lua_ctable;
|
||||
struct lua_cdata
|
||||
{
|
||||
enum LUA_DATATYPE type;
|
||||
size_t data_len; /* 只有在类型为buff或function时使用此标识 */
|
||||
union
|
||||
{
|
||||
int bool;
|
||||
int integer;
|
||||
double number;
|
||||
char *string;
|
||||
|
||||
char *buff;
|
||||
int table;
|
||||
void *pointer;
|
||||
struct lua_context *context;
|
||||
void *function;
|
||||
struct lua_ctable *ctable;
|
||||
};
|
||||
};
|
||||
struct lua_cdata;
|
||||
struct lua_cdata *lua_cdata_new(void);
|
||||
void lua_cdata_free(struct lua_cdata *cdata);
|
||||
struct lua_cdata *lua_cdata_array_new(size_t cdata_num);
|
||||
void lua_cdata_array_free(struct lua_cdata *cdata_array, size_t data_num);
|
||||
struct lua_cdata *lua_cdata_array_get_index(struct lua_cdata *data_array, size_t index);
|
||||
int lua_cdata_data_set(struct lua_cdata *cdata, enum LUA_DATATYPE type, void *value_p, int value_i);
|
||||
int lua_cdata_push_stack(struct lua_state *state, struct lua_cdata *cdata);
|
||||
int lua_cdata_pop_stack(struct lua_state *state, struct lua_cdata *cdata);
|
||||
|
||||
/* ***** ***** ***** ***** ***** ***** */
|
||||
struct lua_fn_arg_pair;
|
||||
struct lua_fn_arg_pair *lua_fn_arg_pair_new(struct lua_module_manager *lua_mod_mgr, int fn_ref_id, int arg_ref_id);
|
||||
void lua_fn_arg_pair_free(struct lua_fn_arg_pair *pair);
|
||||
void lua_fn_arg_pair_insert(struct lua_fn_arg_pair *pair);
|
||||
int lua_fn_arg_pair_get_fn_ref_id(struct lua_fn_arg_pair *pair);
|
||||
int lua_fn_arg_pair_get_arg_ref_id(struct lua_fn_arg_pair *pair);
|
||||
struct lua_module_manager *lua_fn_arg_pair_get_lua_mod_mgr(struct lua_fn_arg_pair *pair);
|
||||
|
||||
/* ***** ***** ***** ***** ***** ***** */
|
||||
typedef int (*lua_cbind_func)(struct lua_state *state);
|
||||
struct lua_state_cbind_func_spec
|
||||
@@ -123,21 +118,11 @@ extern "C"
|
||||
/* ***** ***** ***** ***** ***** ***** */
|
||||
struct lua_state *lua_state_new(struct lua_module_manager *lua_mod_mgr);
|
||||
void lua_state_free(struct lua_state *state);
|
||||
struct lua_module_manager *lua_state_get_lua_module_manager(struct lua_state *state);
|
||||
void *lua_state_get_lua_State(struct lua_state *state);
|
||||
int lua_state_cbinding_function(struct lua_state *state, struct lua_state_cbind_func_spec *bind_func_array, size_t bind_func_num);
|
||||
int lua_state_cbinding_data(struct lua_state *state, struct lua_state_cbind_data_spec *bind_data_array, size_t bind_data_num);
|
||||
int lua_state_copy_ref_value(struct lua_state *to, struct lua_state *from);
|
||||
int lua_state_execute_chunk(struct lua_state *state, int chunk_ref_id, struct lua_cdata *param_array, size_t param_num, struct lua_cdata *return_array, size_t return_num, char *err_log, size_t err_log_len);
|
||||
|
||||
/* ***** ***** ***** ***** ***** ***** */
|
||||
struct lua_fn_arg_pair;
|
||||
struct lua_fn_arg_pair *lua_fn_arg_pair_new(struct lua_module_manager *lua_mod_mgr, int fn_ref_id, int arg_ref_id);
|
||||
void lua_fn_arg_pair_free(struct lua_fn_arg_pair *pair);
|
||||
void lua_fn_arg_pair_insert(struct lua_fn_arg_pair *pair);
|
||||
int lua_fn_arg_pair_get_fn_ref_id(struct lua_fn_arg_pair *pair);
|
||||
int lua_fn_arg_pair_get_arg_ref_id(struct lua_fn_arg_pair *pair);
|
||||
struct lua_module_manager *lua_fn_arg_pair_get_lua_mod_mgr(struct lua_fn_arg_pair *pair);
|
||||
struct lua_module_manager *lua_state_get_lua_module_manager(struct lua_state *state);
|
||||
|
||||
/* ***** ***** ***** ***** ***** ***** */
|
||||
struct lua_module_manager *lua_module_manager_new(struct stellar_module_manager *mod_mgr);
|
||||
@@ -148,8 +133,15 @@ extern "C"
|
||||
int lua_module_manager_duplicate_state(struct lua_module_manager *lua_mod_mgr);
|
||||
void lua_module_manger_pair_list_insert(struct lua_module_manager *lua_mod_mgr, struct lua_fn_arg_pair *pair);
|
||||
int lua_module_manager_call_exit(struct lua_module_manager *lua_mod_mgr);
|
||||
struct lua_state *lua_module_manager_get_current_thread_state(struct lua_module_manager *lua_mod_mgr);
|
||||
struct stellar_module_manager *lua_module_manager_get_stellar_module_manager(struct lua_module_manager *lua_mod_mgr);
|
||||
struct mq_schema *lua_module_manager_get_mq_schema(struct lua_module_manager *lua_mod_mgr);
|
||||
struct mq_runtime *lua_module_manager_get_mq_runtime(struct lua_module_manager *lua_mod_mgr);
|
||||
struct logger *lua_module_manager_get_logger(struct lua_module_manager *lua_mod_mgr);
|
||||
struct packet_manager *lua_module_manager_get_packet_manager(struct lua_module_manager *lua_mod_mgr);
|
||||
struct session_manager *lua_module_manager_get_session_manager(struct lua_module_manager *lua_mod_mgr);
|
||||
int lua_module_manager_get_current_thread_id(struct lua_module_manager *lua_mod_mgr);
|
||||
struct lua_state *lua_module_manager_get_current_thread_state(struct lua_module_manager *lua_mod_mgr);
|
||||
int lua_module_manager_get_max_thread_num(struct lua_module_manager *lua_mod_mgr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user