blob: 5fe2eaf1df67d9b036dbf4ac7127995b5b728813 (
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
|
#ifndef __LUA_BIND_CONTEXT_H__
#define __LUA_BIND_CONTEXT_H__
#include <map>
#include <unordered_set>
#include <unordered_map>
#include "LuaBindRef.h"
#include "LuaBindConfig.h"
#include "LuaBindState.h"
#include "LuaBindGlobalState.h"
namespace LuaBind
{
// ����lua_state��ص�context����һϵ�д����ļ��ϣ�����Ҳû��ϵ����Ҫ��Ϊ�˽�Լ�ڴ档
class VM
{
public:
// ����global_State�õ��������
static VM* TryGetVM(global_State* gState);
static VM* TryGetVM(lua_State* state);
VM();
~VM();
// �������������Ҫ�ֶ�����Setup��������ʼ��һЩ�����״̬��
void Setup();
void OpenLibs();
lua_State* GetMainThread();
void SetCurThread(lua_State* cur);
lua_State* GetCurThread();
lua_State* CreateThread();
State GetMainState();
RefTable& GetStrongRefTable();
RefTable& GetWeakRefTable();
int RegisterNativeClass(State& state, int classID, int index);
void PushClassTable(State& state, int classID);
private:
static std::map<global_State*, VM*> VMs; // ͨ��global_State�����������Ϊ�˷���
global_State* mGlobalState; // �������global_State���ɵ�ǰ������������̹߳���������ע���������GC
lua_State* mMainThread; // ���߳�
lua_State* mCurThread; // ��ǰ�̣߳������Ǿ���ȷ�ģ��ڵ���C����ʱ�����ã���LUA_BIND_STATE��
RefTable mStrongRefTable; // ȫ��ǿ���ñ�
RefTable mWeakRefTable; // ȫ�������ñ�
std::unordered_map<int, StrongRef> mClasses;
#if LUA_BIND_PROFILER
size_t mObjectCount; // ͳ�������ڴ�������д�����ʵ��
#endif
};
}
#endif
|