summaryrefslogtreecommitdiff
path: root/source/external/Luax/luax_vm.h
blob: 3eda3f8488a79d00f892bcc2b58d9a38371e572e (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 __LUAX_CONTEXT_H__
#define __LUAX_CONTEXT_H__

#include <map>
#include <unordered_set>

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

namespace Luax
{

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

		///
		/// global_Stateõ
		///
		static LuaxVM* TryGetVM(global_State* gState);
		static LuaxVM* TryGetVM(lua_State* state);

		LuaxVM();
		~LuaxVM();

		///
		/// ҪֶSetupʼһЩ״̬
		///
		void Setup();

		lua_State* GetMainThread();
		lua_State* CreateThread();
		LuaxState GetMainState();

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

	private:

		typedef std::map<global_State*, LuaxVM*> VMap;

		static VMap VMs;               // ͨglobal_StateΪ˷

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

		global_State* mGlobalState;    // global_Stateɵǰ̹߳
		lua_State*    mMainThread;     // ߳

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

	};

}

#endif