Skip to content

Commit fd7bf34

Browse files
committed
fixed:lua execution failed
modify:loader find module output plugin type
1 parent 1ec593e commit fd7bf34

File tree

6 files changed

+80
-76
lines changed

6 files changed

+80
-76
lines changed

XEngine_Source/XEngine_ModulePlugin/ModulePlugin_Define.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,17 @@ extern "C" BOOL ModulePlugin_Loader_Insert(LPCTSTR lpszModuleMethod, LPCTSTR lps
237237
类型:常量字符指针
238238
可空:N
239239
意思:输入要执行的方法
240+
参数.二:pInt_Type
241+
In/Out:Out
242+
类型:整数型指针
243+
可空:N
244+
意思:输出获取到的模块类型
240245
返回值
241246
类型:逻辑型
242247
意思:是否成功
243248
备注:
244249
*********************************************************************/
245-
extern "C" BOOL ModulePlugin_Loader_Find(LPCTSTR lpszMethodName);
250+
extern "C" BOOL ModulePlugin_Loader_Find(LPCTSTR lpszMethodName, int* pInt_Type);
246251
/********************************************************************
247252
函数名称:ModulePlugin_Loader_Exec
248253
函数功能:执行一次插件

XEngine_Source/XEngine_ModulePlugin/ModulePlugin_Error.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@
2222
#define ERROR_XENGINE_APISERVICE_MODULE_PLUGIN_INIT 0xE1007 //初始化内部模块失败
2323
#define ERROR_XENGINE_APISERVICE_MODULE_PLUGIN_NOTFOUND 0xE1008 //没有找到句柄
2424
#define ERROR_XENGINE_APISERVICE_MODULE_PLUGIN_ISINITED 0xE1009 //已经初始化了,不需要再次初始化
25-
#define ERROR_XENGINE_APISERVICE_MODULE_PLUGIN_EXECTION 0xE100A //插件执行失败
25+
#define ERROR_XENGINE_APISERVICE_MODULE_PLUGIN_EXECTION 0xE100A //插件执行失败
26+
#define ERROR_XENGINE_APISERVICE_MODULE_PLUGIN_MALLOC 0xE100B //申请内存失败

XEngine_Source/XEngine_ModulePlugin/ModulePlugin_Loader/ModulePlugin_Loader.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,17 @@ BOOL CModulePlugin_Loader::ModulePlugin_Loader_Insert(LPCTSTR lpszModuleMethod,
8888
类型:常量字符指针
8989
可空:N
9090
意思:输入要执行的方法
91+
参数.二:pInt_Type
92+
In/Out:Out
93+
类型:整数型指针
94+
可空:N
95+
意思:输出获取到的模块类型
9196
返回值
9297
类型:逻辑型
9398
意思:是否成功
9499
备注:
95100
*********************************************************************/
96-
BOOL CModulePlugin_Loader::ModulePlugin_Loader_Find(LPCTSTR lpszMethodName)
101+
BOOL CModulePlugin_Loader::ModulePlugin_Loader_Find(LPCTSTR lpszMethodName, int* pInt_Type)
97102
{
98103
ModulePlugin_IsErrorOccur = FALSE;
99104

@@ -112,6 +117,10 @@ BOOL CModulePlugin_Loader::ModulePlugin_Loader_Find(LPCTSTR lpszMethodName)
112117
st_Locker.unlock_shared();
113118
return FALSE;
114119
}
120+
if (NULL != pInt_Type)
121+
{
122+
*pInt_Type = stl_MapIterator->second.nType;
123+
}
115124
st_Locker.unlock_shared();
116125
return TRUE;
117126
}

XEngine_Source/XEngine_ModulePlugin/ModulePlugin_Loader/ModulePlugin_Loader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CModulePlugin_Loader
2525
~CModulePlugin_Loader();
2626
public:
2727
BOOL ModulePlugin_Loader_Insert(LPCTSTR lpszModuleMethod, LPCTSTR lpszModuleName, int nType = 0);
28-
BOOL ModulePlugin_Loader_Find(LPCTSTR lpszMethodName);
28+
BOOL ModulePlugin_Loader_Find(LPCTSTR lpszMethodName, int* pInt_Type);
2929
BOOL ModulePlugin_Loader_Exec(LPCTSTR lpszMethodName, TCHAR*** pppHDRList, int nListCount, int* pInt_HTTPCode, TCHAR* ptszMsgBuffer, int* pInt_MsgLen);
3030
BOOL ModulePlugin_Loader_Destory();
3131
protected:

XEngine_Source/XEngine_ModulePlugin/ModulePlugin_LuaCore/ModulePlugin_LuaCore.cpp

Lines changed: 59 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -144,62 +144,48 @@ BOOL CModulePlugin_LuaCore::ModulePlugin_LuaCore_Exec(XNETHANDLE xhModule, TCHAR
144144
st_csStl.unlock_shared();
145145
return FALSE;
146146
}
147-
148-
if (0 == lua_getglobal(stl_MapIterator->second.pSt_LuaState, "PluginCore_Call1"))
147+
if (0 == lua_getglobal(stl_MapIterator->second.pSt_LuaState, "PluginCore_Call"))
149148
{
149+
ModulePlugin_IsErrorOccur = TRUE;
150+
ModulePlugin_dwErrorCode = ERROR_XENGINE_APISERVICE_MODULE_PLUGIN_FPCALL;
151+
st_csStl.unlock_shared();
150152
return FALSE;
151153
}
154+
TCHAR tszURLParam[MAX_PATH];
155+
memset(tszURLParam, '\0', MAX_PATH);
152156

153-
lua_pushstring(stl_MapIterator->second.pSt_LuaState, "1");
154-
lua_pushstring(stl_MapIterator->second.pSt_LuaState, "2");
155-
lua_pushinteger(stl_MapIterator->second.pSt_LuaState, 3);
156-
int nRet = lua_pcall(stl_MapIterator->second.pSt_LuaState, 3, 0, 0);
157-
158-
lua_getglobal(stl_MapIterator->second.pSt_LuaState, "pInt_HTTPCode");
159-
*pInt_HTTPCode = lua_tonumber(stl_MapIterator->second.pSt_LuaState, -1);
160-
lua_pop(stl_MapIterator->second.pSt_LuaState, -1);
161-
162-
lua_getglobal(stl_MapIterator->second.pSt_LuaState, "pInt_MsgLen");
163-
*pInt_MsgLen = lua_tonumber(stl_MapIterator->second.pSt_LuaState, -1);
157+
for (int i = 1; i < nListCount; i++)
158+
{
159+
if (i > 1)
160+
{
161+
_tcscat(tszURLParam, "&");
162+
}
163+
_tcscat(tszURLParam, (*pppHDRList)[i]);
164+
}
165+
lua_pushstring(stl_MapIterator->second.pSt_LuaState, tszURLParam);
166+
lua_pushinteger(stl_MapIterator->second.pSt_LuaState, nListCount - 1);
167+
lua_pushstring(stl_MapIterator->second.pSt_LuaState, lpszMsgBufer);
168+
lua_pushinteger(stl_MapIterator->second.pSt_LuaState, nMsgLen);
169+
if (LUA_OK != lua_pcall(stl_MapIterator->second.pSt_LuaState, 4, 1, 0))
170+
{
171+
ModulePlugin_IsErrorOccur = TRUE;
172+
ModulePlugin_dwErrorCode = ERROR_XENGINE_APISERVICE_MODULE_PLUGIN_EXECTION;
173+
st_csStl.unlock_shared();
174+
return FALSE;
175+
}
176+
lua_getglobal(stl_MapIterator->second.pSt_LuaState, "PInt_HTTPCode");
177+
*pInt_HTTPCode = (int)lua_tonumber(stl_MapIterator->second.pSt_LuaState, -1);
164178
lua_pop(stl_MapIterator->second.pSt_LuaState, -1);
165179

166-
lua_getglobal(stl_MapIterator->second.pSt_LuaState, "ptszMsgBuffer");
167-
LPCTSTR lpszStr = lua_tostring(stl_MapIterator->second.pSt_LuaState, -1);
180+
lua_getglobal(stl_MapIterator->second.pSt_LuaState, "PtszMsgBuffer");
181+
_tcscpy(ptszMsgBuffer, lua_tostring(stl_MapIterator->second.pSt_LuaState, -1));
168182
lua_pop(stl_MapIterator->second.pSt_LuaState, -1);
169-
/*
170-
lua_newtable(stl_MapIterator->second.pSt_LuaState);
171-
for (int i = 0; i < nListCount; i++)
172-
{
173-
TCHAR tszStrKey[64];
174-
TCHAR tszStrValue[64];
175-
176-
memset(tszStrKey, '\0', sizeof(tszStrKey));
177-
memset(tszStrValue, '\0', sizeof(tszStrValue));
178-
BaseLib_OperatorString_GetKeyValue((*pppHDRList)[i], "=", tszStrKey, tszStrValue);
179-
180-
lua_pushstring(stl_MapIterator->second.pSt_LuaState, tszStrKey);
181-
lua_pushstring(stl_MapIterator->second.pSt_LuaState, tszStrValue);
182-
lua_settable(stl_MapIterator->second.pSt_LuaState, -3);
183-
}
184-
lua_pushnumber(stl_MapIterator->second.pSt_LuaState, nListCount);
185-
186-
int nRet = 0;
187-
if (NULL == lpszMsgBufer)
188-
{
189-
lua_pushstring(stl_MapIterator->second.pSt_LuaState, "");
190-
lua_pushinteger(stl_MapIterator->second.pSt_LuaState, 0);
191183

192-
nRet = lua_pcall(stl_MapIterator->second.pSt_LuaState, 7, 1, 0);
193-
}
194-
else
195-
{
196-
lua_pushstring(stl_MapIterator->second.pSt_LuaState, lpszMsgBufer);
197-
lua_pushinteger(stl_MapIterator->second.pSt_LuaState, nMsgLen);
184+
lua_getglobal(stl_MapIterator->second.pSt_LuaState, "PInt_MsgLen");
185+
*pInt_MsgLen = (int)lua_tonumber(stl_MapIterator->second.pSt_LuaState, -1);
186+
lua_pop(stl_MapIterator->second.pSt_LuaState, -1);
198187

199-
nRet = lua_pcall(stl_MapIterator->second.pSt_LuaState, 7, 1, 0);
200-
}
201-
*/
202-
st_csStl.unlock_shared();
188+
st_csStl.unlock_shared();
203189

204190
return TRUE;
205191
}
@@ -280,42 +266,45 @@ BOOL CModulePlugin_LuaCore::ModulePlugin_LuaCore_Add(XNETHANDLE xhNet, LPCTSTR l
280266

281267
if (NULL == st_LuaCore.pSt_LuaState)
282268
{
269+
ModulePlugin_IsErrorOccur = TRUE;
270+
ModulePlugin_dwErrorCode = ERROR_XENGINE_APISERVICE_MODULE_PLUGIN_MALLOC;
283271
return FALSE;
284272
}
285273
luaL_openlibs(st_LuaCore.pSt_LuaState);
286274

287-
if (0 != luaL_loadfile(st_LuaCore.pSt_LuaState, lpszPluginFile))
275+
if (LUA_OK != luaL_loadfile(st_LuaCore.pSt_LuaState, lpszPluginFile))
288276
{
289-
return FALSE;
290-
}
291-
if (0 != lua_pcall(st_LuaCore.pSt_LuaState, 0, 0, 0))
292-
{
293-
return FALSE;
277+
ModulePlugin_IsErrorOccur = TRUE;
278+
ModulePlugin_dwErrorCode = ERROR_XENGINE_APISERVICE_MODULE_PLUGIN_OPENDL;
279+
return FALSE;
294280
}
281+
if (LUA_OK != lua_pcall(st_LuaCore.pSt_LuaState, 0, 0, 0))
282+
{
283+
ModulePlugin_IsErrorOccur = TRUE;
284+
ModulePlugin_dwErrorCode = ERROR_XENGINE_APISERVICE_MODULE_PLUGIN_EXECTION;
285+
return FALSE;
286+
}
295287

296288
if (0 == lua_getglobal(st_LuaCore.pSt_LuaState, "PluginCore_Init"))
297289
{
298-
return FALSE;
299-
}
300-
if (NULL == lParam)
301-
{
302-
if (LUA_OK != lua_pcall(st_LuaCore.pSt_LuaState, 0, 1, 0))
303-
{
304-
return FALSE;
305-
}
306-
}
307-
else
308-
{
309-
lua_pushlightuserdata(st_LuaCore.pSt_LuaState, lParam);
310-
if (LUA_OK != lua_pcall(st_LuaCore.pSt_LuaState, 1, 1, 0))
311-
{
312-
return FALSE;
313-
}
290+
ModulePlugin_IsErrorOccur = TRUE;
291+
ModulePlugin_dwErrorCode = ERROR_XENGINE_APISERVICE_MODULE_PLUGIN_FPINIT;
292+
return FALSE;
314293
}
294+
295+
if (LUA_OK != lua_pcall(st_LuaCore.pSt_LuaState, 0, 1, 0))
296+
{
297+
ModulePlugin_IsErrorOccur = TRUE;
298+
ModulePlugin_dwErrorCode = ERROR_XENGINE_APISERVICE_MODULE_PLUGIN_EXECTION;
299+
return FALSE;
300+
}
315301
if (!lua_toboolean(st_LuaCore.pSt_LuaState, -1))
316302
{
317-
return FALSE;
303+
ModulePlugin_IsErrorOccur = TRUE;
304+
ModulePlugin_dwErrorCode = ERROR_XENGINE_APISERVICE_MODULE_PLUGIN_EXECTION;
305+
return FALSE;
318306
}
307+
lua_pop(st_LuaCore.pSt_LuaState, -1);
319308

320309
st_csStl.lock();
321310
stl_MapFrameWork.insert(make_pair(xhNet, st_LuaCore));

XEngine_Source/XEngine_ModulePlugin/pch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ extern "C" BOOL ModulePlugin_Loader_Insert(LPCTSTR lpszModuleMethod, LPCTSTR lps
7575
{
7676
return m_PluginLoader.ModulePlugin_Loader_Insert(lpszModuleMethod, lpszModuleName, nType);
7777
}
78-
extern "C" BOOL ModulePlugin_Loader_Find(LPCTSTR lpszMethodName)
78+
extern "C" BOOL ModulePlugin_Loader_Find(LPCTSTR lpszMethodName, int* pInt_Type)
7979
{
80-
return m_PluginLoader.ModulePlugin_Loader_Find(lpszMethodName);
80+
return m_PluginLoader.ModulePlugin_Loader_Find(lpszMethodName, pInt_Type);
8181
}
8282
extern "C" BOOL ModulePlugin_Loader_Exec(LPCTSTR lpszMethodName, TCHAR * **pppHDRList, int nListCount, int* pInt_HTTPCode, TCHAR * ptszMsgBuffer, int* pInt_MsgLen)
8383
{

0 commit comments

Comments
 (0)