summaryrefslogtreecommitdiff
path: root/source/3rd-party/Luax/luax_runtime.h
blob: 27c9af44d4bfc94870cc6904b2524e8f4a3fa16b (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 __LUAX_RUNTIME_H__
#define __LUAX_RUNTIME_H__

#include <map>

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

namespace Luax
{

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

		static LuaxRuntime& Get();

		///
		/// һµluaʹ̲߳صlua_State*һ8\4ֽڵkey
		///
		lua_State* Open();
/*
		///
		/// ̴߳һ̡߳ӵcontextӳ䡣ҪΪ˷context߳ʡ
		///
		lua_State* CreateThread(lua_State* mainThread);
*/
		///
		/// ر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);

		LuaxVM& operator[](lua_State* L);

	private:

		LuaxRuntime();
		~LuaxRuntime();

		static LuaxRuntime* mRuntime;

		///
		/// lua_State handlecontextӳ
		///
		std::map<lua_State*, LuaxVM*> mContexts;

	};

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

}

#endif