summaryrefslogtreecommitdiff
path: root/source/3rd-party/Luax/luax_vm.h
blob: 9039a046cd0ca358d60dfc2f3349e989906b487a (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
#ifndef __LUAX_CONTEXT_H__
#define __LUAX_CONTEXT_H__

#include <map>
#include <unordered_set>

#include "luax_ref.h"
#include "luax_config.h"
#include "luax_state.h"

namespace Luax
{

	///
	/// lua_stateصcontextһϵдļϣҲûϵҪΪ˽Լڴ档
	///
	class LuaxVM
	{
	public:
		LuaxVM();
		~LuaxVM();

		void Setup();

		lua_State* CreateThread();
		lua_State* GetMainThread();

		int GetThreadCount();

		LuaxRefTable& GetStrongRefTable();
		LuaxRefTable& GetWeakRefTable();

		bool HasThread(lua_State* L);

		static LuaxVM* TryGetVM(lua_State* L);

		typedef std::map<lua_State*, LuaxVM*> ThreadMap;

	private:

		static ThreadMap threadMap;   // ̲ͨ߳Ϊ˷

		LuaxRefTable mStrongRefTable; // _LUAX_STRONGREF_TABLE
		LuaxRefTable mWeakRefTable;   // _LUAX_WEAKREF_TABLE

		lua_State*   mMainThread;     // ߳

		std::unordered_set<lua_State*> mThreads; // ߳

#if LUAX_PROFILER
		size_t       mObjectCount;    // ͳڴдʵ
#endif

	};

}

#endif