Skip to content

Commit c7cb3ca

Browse files
committed
dd
1 parent 16efcc5 commit c7cb3ca

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

bsn_cpp/_run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

33
pushd out
4-
./bsn_2_plug_mgr_loader_d config.lua
4+
./bsn_2_plug_mgr_loader_d ../config.lua
55
popd
66

bsn_cpp/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("sssss")

bsn_cpp/plug_mgr/include/i_plug_mgr.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class I_PlugMgr : public std::enable_shared_from_this<I_PlugMgr> {
2929
virtual bool IsQuit() = 0;
3030

3131
virtual T_IOService& GetIOService() = 0;
32+
virtual lua_State* GetLuaState() const = 0;
3233

3334
public:
3435
T_SPI_PlugMgr GetSPI_PlugMgr() {
@@ -49,9 +50,6 @@ class I_PlugMgr : public std::enable_shared_from_this<I_PlugMgr> {
4950

5051
public:
5152
virtual ~I_PlugMgr() = default;
52-
53-
protected:
54-
lua_State* m_pLuaState;
5553
};
5654
//////////////////////////////////////////////////////////////////////
5755
D_BsnNamespace1End

bsn_cpp/plug_mgr/src/plug_mgr.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,22 @@ C_PlugMgr::C_PlugMgr()
4646

4747
m_bHadQuitAll = false;
4848

49+
m_pLuaState = lua_open();
50+
lua_gc(m_pLuaState, LUA_GCSTOP, 0); /* stop collector during initialization */
51+
luaL_openlibs(m_pLuaState);
52+
lua_gc(m_pLuaState, LUA_GCRESTART, -1);
53+
4954
C_PlugData::RegPlugData();
5055
}
5156

5257
C_PlugMgr::~C_PlugMgr() {
5358
D_OutInfo();
5459

60+
lua_close(m_pLuaState);
61+
}
62+
63+
lua_State* C_PlugMgr::GetLuaState() const {
64+
return m_pLuaState;
5565
}
5666

5767
C_PlugMgr::T_IOService& C_PlugMgr::GetIOService() {
@@ -61,7 +71,9 @@ C_PlugMgr::T_IOService& C_PlugMgr::GetIOService() {
6171
void C_PlugMgr::Run(char const * pszConfigFile) {
6272
D_OutInfo2("pszConfigFile=", pszConfigFile);
6373
m_strConfigFile = pszConfigFile;
64-
74+
75+
luaL_dofile(m_pLuaState, pszConfigFile);
76+
6577
if (!LoadAll()) {
6678
D_OutInfo1("LoadAll fail");
6779
return;

bsn_cpp/plug_mgr/src/plug_mgr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class C_PlugMgr : public I_PlugMgr {
2727
virtual bool IsQuit() override;
2828

2929
virtual boost::asio::io_service& GetIOService() override;
30+
virtual lua_State* GetLuaState() const override;
3031

3132
public:
3233
static T_SPC_PlugMgr NewC_PlugMgr();
@@ -59,6 +60,7 @@ class C_PlugMgr : public I_PlugMgr {
5960
std::string m_waitReloadPlug;
6061
bool m_bHadQuitAll;
6162
std::string m_strConfigFile;
63+
lua_State* m_pLuaState;
6264

6365
public:
6466
C_PlugMgr();

0 commit comments

Comments
 (0)