summaryrefslogtreecommitdiff
path: root/Source/3rdParty/Luax/luax_runtime.h
blob: 2414c2ed817e9edf58d9f9153b192c49b680b2b0 (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
68
69
70
71
#ifndef __LUAX_RUNTIME_H__
#define __LUAX_RUNTIME_H__

#include <map>

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

namespace Luax
{

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

		LuaxState    state;          // lua state
		LuaxRefTable strongRefTable; // strong ref table
		LuaxRefTable weakRefTable;   // weak ref table

		size_t objectCount;          // ͳڴstateдʵ

	};

	///
	/// ͳһеlua states
	///
	class LuaxRuntime
	{
	public:

		static LuaxRuntime& Get();

		///
		/// һµlua_Stateصlua_State*һ8\4ֽڵkey
		///
		lua_State* Open();

		///
		/// رlua_Stateruntimeɾ
		///
		void Close(lua_State* L);

		bool          HasLuaxState(lua_State* L);
		LuaxState&    GetLuaxState(lua_State* L);
		LuaxRefTable& GetStrongRefTable(lua_State* L);
		LuaxRefTable& GetWeaksRefTable(lua_State* L);

		Context& operator[](lua_State* L);

	private:

		LuaxRuntime();
		~LuaxRuntime();

		static LuaxRuntime* mRuntime;

		///
		/// lua_stateҵcontext
		///
		std::map<lua_State*, Context> mContexts;

	};

}

#endif