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_State²¢½«Æä´ÓruntimeÖÐɾ³ý¡£
		///
		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 handleµ½contextµÄÓ³Éä
		///
		std::map<lua_State*, LuaxVM*> mContexts;

	};

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

}

#endif