Skip to content

Commit 616a9c5

Browse files
committed
modify:get info function support for lua plugin
1 parent d0392d1 commit 616a9c5

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

XEngine_Source/XEngine_ModulePlugin/ModulePlugin_LibCore/ModulePlugin_LibCore.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,8 @@ bool CModulePlugin_LibCore::ModulePlugin_LibCore_Destroy()
178178
unordered_map<XNETHANDLE, PLUGINCORE_FRAMEWORK>::iterator stl_MapIterator = stl_MapFrameWork.begin();
179179
for (; stl_MapIterator != stl_MapFrameWork.end(); stl_MapIterator++)
180180
{
181-
stl_MapIterator->second.fpCall_PluginCore_UnInit();
182-
#ifdef _MSC_BUILD
183-
FreeLibrary(stl_MapIterator->second.mhFile);
184-
#else
185-
dlclose(stl_MapIterator->second.mhFile);
186-
#endif
181+
stl_MapIterator->second.fpCall_PluginCore_UnInit();
182+
XFreeModule(stl_MapIterator->second.mhFile);
187183
}
188184
stl_MapFrameWork.clear();
189185
st_csStl.unlock();
@@ -307,13 +303,7 @@ bool CModulePlugin_LibCore::ModulePlugin_LibCore_Add(XNETHANDLE xhNet, LPCXSTR l
307303
return false;
308304
}
309305
//获得内部模块信息
310-
if (!st_FrameWork.fpCall_PluginCore_GetInfo(st_FrameWork.tszModuleName, st_FrameWork.tszModuleVer, st_FrameWork.tszModuleAuthor, st_FrameWork.tszModuleDesc))
311-
{
312-
XFreeModule(st_FrameWork.mhFile);
313-
ModulePlugin_IsErrorOccur = true;
314-
ModulePlugin_dwErrorCode = ERROR_XENGINE_APISERVICE_MODULE_PLUGIN_INIT;
315-
return false;
316-
}
306+
st_FrameWork.fpCall_PluginCore_GetInfo(st_FrameWork.tszModuleName, st_FrameWork.tszModuleVer, st_FrameWork.tszModuleAuthor, st_FrameWork.tszModuleDesc);
317307
_tcsxcpy(st_FrameWork.tszModuleFile, lpszPluginFile);
318308

319309
//添加模块属性到STL函数中

XEngine_Source/XEngine_ModulePlugin/ModulePlugin_LibCore/ModulePlugin_LibCore.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*********************************************************************/
1313
typedef bool(*FPCall_PluginCore_Init)(XPVOID lParam);
1414
typedef void(*FPCall_PluginCore_UnInit)();
15-
typedef bool(*FPCall_PluginCore_GetInfo)(XCHAR* ptszPluginName, XCHAR* ptszPluginVersion, XCHAR* ptszPluginAuthor, XCHAR* ptszPluginDesc);
15+
typedef void(*FPCall_PluginCore_GetInfo)(XCHAR* ptszPluginName, XCHAR* ptszPluginVersion, XCHAR* ptszPluginAuthor, XCHAR* ptszPluginDesc);
1616
typedef bool(*FPCall_PluginCore_Call)(XCHAR*** pppHDRList, int nListCount, int* pInt_HTTPCode, XCHAR* ptszMsgBuffer, int* pInt_MsgLen, LPCXSTR lpszMsgBufer, int nMsgLen);
1717
typedef XLONG(*FPCall_PluginCore_GetLastError)();
1818

@@ -31,7 +31,7 @@ typedef struct
3131

3232
bool(*fpCall_PluginCore_Init)(XPVOID lParam);
3333
void(*fpCall_PluginCore_UnInit)();
34-
bool(*fpCall_PluginCore_GetInfo)(XCHAR* ptszPluginName, XCHAR* ptszPluginVersion, XCHAR* ptszPluginAuthor, XCHAR* ptszPluginDesc);
34+
void(*fpCall_PluginCore_GetInfo)(XCHAR* ptszPluginName, XCHAR* ptszPluginVersion, XCHAR* ptszPluginAuthor, XCHAR* ptszPluginDesc);
3535
bool(*fpCall_PluginCore_Call)(XCHAR*** pppHDRList, int nListCount, int* pInt_HTTPCode, XCHAR* ptszMsgBuffer, int* pInt_MsgLen, LPCXSTR lpszMsgBufer, int nMsgLen);
3636
XLONG(*fpCall_PluginCore_GetLastError)();
3737
}PLUGINCORE_FRAMEWORK, * LPPLUGINCORE_FRAMEWORK;

XEngine_Source/XEngine_ModulePlugin/ModulePlugin_LuaCore/ModulePlugin_LuaCore.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ bool CModulePlugin_LuaCore::ModulePlugin_LuaCore_Add(XNETHANDLE xhNet, LPCXSTR l
273273
ModulePlugin_dwErrorCode = ERROR_XENGINE_APISERVICE_MODULE_PLUGIN_EXECTION;
274274
return false;
275275
}
276-
276+
//得到初始化函数
277277
if (0 == lua_getglobal(st_LuaCore.pSt_LuaState, "PluginCore_Init"))
278278
{
279279
ModulePlugin_IsErrorOccur = true;
@@ -294,6 +294,31 @@ bool CModulePlugin_LuaCore::ModulePlugin_LuaCore_Add(XNETHANDLE xhNet, LPCXSTR l
294294
return false;
295295
}
296296
lua_pop(st_LuaCore.pSt_LuaState, -1);
297+
//得到信息函数
298+
if (0 == lua_getglobal(st_LuaCore.pSt_LuaState, "PluginCore_GetInfo"))
299+
{
300+
ModulePlugin_IsErrorOccur = true;
301+
ModulePlugin_dwErrorCode = ERROR_XENGINE_APISERVICE_MODULE_PLUGIN_FPINIT;
302+
return false;
303+
}
304+
if (LUA_OK != lua_pcall(st_LuaCore.pSt_LuaState, 0, 4, 0))
305+
{
306+
ModulePlugin_IsErrorOccur = true;
307+
ModulePlugin_dwErrorCode = ERROR_XENGINE_APISERVICE_MODULE_PLUGIN_EXECTION;
308+
return false;
309+
}
310+
if (!lua_toboolean(st_LuaCore.pSt_LuaState, -1))
311+
{
312+
ModulePlugin_IsErrorOccur = true;
313+
ModulePlugin_dwErrorCode = ERROR_XENGINE_APISERVICE_MODULE_PLUGIN_EXECTION;
314+
return false;
315+
}
316+
// Lua 栈从右到左是逆序压栈的,所以要从 -4 开始取
317+
_tcsxcpy(st_LuaCore.tszModuleName, lua_tostring(st_LuaCore.pSt_LuaState, -4));
318+
_tcsxcpy(st_LuaCore.tszModuleVer, lua_tostring(st_LuaCore.pSt_LuaState, -3));
319+
_tcsxcpy(st_LuaCore.tszModuleAuthor, lua_tostring(st_LuaCore.pSt_LuaState, -2));
320+
_tcsxcpy(st_LuaCore.tszModuleDesc, lua_tostring(st_LuaCore.pSt_LuaState, -1));
321+
lua_pop(st_LuaCore.pSt_LuaState, 4);
297322

298323
st_csStl.lock();
299324
stl_MapFrameWork.insert(make_pair(xhNet, st_LuaCore));

XEngine_Source/XEngine_ModulePlugin/ModulePlugin_LuaCore/ModulePlugin_LuaCore.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
typedef struct
1414
{
1515
XCHAR tszModuleFile[XPATH_MAX];
16+
XCHAR tszModuleName[128];
17+
XCHAR tszModuleAuthor[128];
18+
XCHAR tszModuleDesc[128];
19+
XCHAR tszModuleVer[64];
1620
#if (1 == _XENGINE_BUILD_SWITCH_LUA)
1721
lua_State* pSt_LuaState;
1822
#endif

0 commit comments

Comments
 (0)