summaryrefslogtreecommitdiff
path: root/Source/3rdParty/Luax/luax_runtime.h
blob: cb8b66be99bd74abb02418d38847998802aedb23 (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
#ifndef __LUAX_RUNTIME_H__
#define __LUAX_RUNTIME_H__

#include <map>

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

namespace Luax
{

	///
	/// ͳһе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 handlecontextӳ
		///
		std::map<lua_State*, Context> mContexts;

	};

#define LUAX_RUNTIME() \
	LuaxRuntime& runtime = LuaxRuntime::Get()

}

#endif