blob: 0d4c2d441ad64dc3feca502b1407904f10223db7 (
plain)
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
|
#ifndef __LUA_BIND_REFTABLE_H__
#define __LUA_BIND_REFTABLE_H__
#include "LuaBindConfig.h"
namespace LuaBind
{
class State;
//
// ref table 管理,对strong ref table和weak ref table两个table的代理。
//
class RefTable
{
public:
enum
{
WEAK_KEY = 1,
WEAK_VALUE = 1 << 1
};
RefTable();
~RefTable();
inline operator bool() { return mState; };
void Init(State& state, cc8* name, cc8* mode = nullptr);
bool IsKeyWeak();
bool IsValueWeak();
//
// 对stack[idx]的实体在此ref table中增加一个引用,并返回refID
//
int Ref(State& state, int idx);
void Unref(State& state, int refID);
//
// 将此 ref table 放在栈顶
//
void PushRefTable(State& state);
//
// 将 reftable[refID] 放在栈顶
//
void PushRef(State& state, int refID);
//
// 清空 ref table,表还留在LUA_REGISTRYINDEX[mName]
//
void Clear(State& state);
private:
friend class State;
lua_State* mState; // 用来做一些确认工作
cc8* mName; // ref table的名称
int mMode; // ref table的类型
};
}
#endif
|