summaryrefslogtreecommitdiff
path: root/source/libs/asura-lib-utils/scripting/lua_env.h
blob: 3bef3df328cbb87610b959540d07b33a79402623 (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
72
73
74
75
76
#ifndef __ASURA_LUA_ENV_H__
#define __ASURA_LUA_ENV_H__

extern "C"
{
#include <Lua51/lua.h>
#include <Lua51/lauxlib.h>
}
#include <Luax/luax.h>

#include "../singleton.hpp"

namespace AsuraEngine
{
	namespace Scripting
	{

		///
		/// ͨӿڷlua stateAsura˼ǣ߳άһluaӦõҪ߼ڴlua
		/// ߳߽ջ
		///
		class LuaEnv ASURA_FINAL : public Singleton<LuaEnv>
		{
		public:

			LuaEnv() : mMainState(0) {};
			~LuaEnv() {};

			///
			/// ִջ
			///
			inline void Init() 
			{ 
				ASSERT(!mMainState);
				// ߳
				mMainState = Luax::LuaxRuntime::Get().Open();
				ASSERT(mMainState);
			};

			inline lua_State* GetMainState()
			{ 
				return mMainState; 
			};

			inline Luax::LuaxState& GetMainLuaxState() 
			{ 
				return Luax::LuaxRuntime::Get()[mMainState].state;
			};

			inline void Exit()
			{
				Luax::LuaxRuntime::Get().Close(mMainState);
			}

		private:

			///
			/// ̱߳һluaһAsuraԶֻһ󲿷ִ붼УֻһΡ
			/// ߳\ִջӦglobal_Stateģ
			///
			///	    struct lua_State *mainthread;
			///
			/// ʹlua_newstate()ᴴһһglobal_Stateṹһ߳lua_Stateء
			/// global_State̹߳˵һ߳lua_newstate()⣬߳lua_newthread()
			/// 
			///
			lua_State* mMainState;

		};

	}
}

namespace AEScripting = AsuraEngine::Scripting;

#endif