-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMsgEx.h
76 lines (60 loc) · 1.12 KB
/
MsgEx.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef __MSG_EX_H__
#define __MSG_EX_H__
#include "Lunar.h"
#include <string.h>
#include <assert.h>
#define MAX_BUF_LEN 50
class Msg {
public:
Msg(int id){
m_msgId = id;
m_buf = new char[MAX_BUF_LEN];
memset(m_buf, '\0', sizeof(m_buf));
}
~Msg(){
delete[] m_buf;
m_buf = NULL;
}
void ToString() {
printf("msgId: %d===buf: %s\n", m_msgId, m_buf);
}
public: //for simplifying
int m_msgId;
char* m_buf;
};
class MsgEx
{
public:
MsgEx(){
m_pMsg = new Msg(0);
}
~MsgEx(){
delete m_pMsg;
m_pMsg = NULL;
}
inline Msg* GetMsg(){
return m_pMsg;
}
inline void SetMsg(Msg* pMsg){
m_pMsg = pMsg;
}
private:
Msg *m_pMsg;
};
struct lua_State;
class LuaMsgEx
{
public:
LuaMsgEx(lua_State *pL){
m_pMsgEx = (MsgEx*)lua_touserdata(pL, -1);
}
int ReadMsg(lua_State* pL);
int WriteMsg(lua_State* pL);
int Print(lua_State* pL);
void NotRegisted();
const static char className [] ;
static Lunar<LuaMsgEx>::RegType methods[];
private:
MsgEx* m_pMsgEx;
};
#endif //__MSG_EX_H__