blob: dcff44fe4baba842ed8547a7e95edda827b6e54f (
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
|
#ifndef __LUA_BIND_CONTEXT_H__
#define __LUA_BIND_CONTEXT_H__
#include <map>
#include <unordered_set>
#include "LuaBindRef.h"
#include "LuaBindConfig.h"
#include "LuaBindState.h"
#include "LuaBindGlobalState.h"
namespace LuaBind
{
///
/// 单个lua_state相关的context。是一系列代理的集合,拷贝也没关系,主要是为了节约内存。
///
class LuaBindVM
{
public:
///
/// 根据global_State拿到虚拟机。
///
static LuaBindVM* TryGetVM(global_State* gState);
static LuaBindVM* TryGetVM(lua_State* state);
LuaBindVM();
~LuaBindVM();
///
/// 创建虚拟机后,需要手动调用Setup函数,初始化一些虚拟机状态。
///
void Setup();
lua_State* GetMainThread();
lua_State* CreateThread();
LuaBindState GetMainState();
LuaBindRefTable& GetStrongRefTable();
LuaBindRefTable& GetWeakRefTable();
private:
typedef std::map<global_State*, LuaBindVM*> VMap;
static VMap VMs; // 通过global_State索引虚拟机,为了方便
LuaBindRefTable mStrongRefTable; // _LUA_BIND_STRONGREF_TABLE
LuaBindRefTable mWeakRefTable; // _LUA_BIND_WEAKREF_TABLE
global_State* mGlobalState; // 虚拟机的global_State,由当前虚拟机的所有线程共享
lua_State* mMainThread; // 主线程
#if LUA_BIND_PROFILER
size_t mObjectCount; // 统计所有在此虚拟机中创建的实例
#endif
};
}
#endif
|