summaryrefslogtreecommitdiff
path: root/Source/external/Luax/luax_reftable.h
blob: 58e4b9c06ff5cf90e2296fc10356801cf4c56bc0 (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
#ifndef __LUAX_REFTABLE_H__
#define __LUAX_REFTABLE_H__

#include "luax_config.h"

namespace Luax
{

	class LuaxState;

	///
	/// ref table ¹ÜÀí£¬¶Ôstrong ref tableºÍweak ref tableÁ½¸ötableµÄ´úÀí¡£
	///
	class LuaxRefTable
	{
	public:

		enum
		{
			WEAK_KEY   = 1, 
			WEAK_VALUE = 1 << 1
		};

		LuaxRefTable();
		~LuaxRefTable();

		inline operator bool() { return mState; };

		void Init(LuaxState& state, cc8* name, cc8* mode = nullptr);

		bool IsKeyWeak();
		bool IsValueWeak();

		///
		/// ¶Ôstack[idx]µÄʵÌåÔÚ´Ëref tableÖÐÔö¼ÓÒ»¸öÒýÓ㬲¢·µ»ØrefID
		///
		int Ref(LuaxState& state, int idx);
		void Unref(LuaxState& state, int refID);

		///
		/// ½«´Ë ref table ·ÅÔÚÕ»¶¥
		///
		void PushRefTable(LuaxState& state);

		///
		/// ½« reftable[refID] ·ÅÔÚÕ»¶¥
		///
		void PushRef(LuaxState& state, int refID);

		///
		/// Çå¿Õ ref table£¬±í»¹ÁôÔÚLUA_REGISTRYINDEX[mName]
		///
		void Clear(LuaxState& state);

	private:

		friend class LuaxState;

		lua_State* mState; // ÓÃÀ´×öһЩȷÈϹ¤×÷
		cc8*       mName;  // ref tableµÄÃû³Æ
		int        mMode;  // ref tableµÄÀàÐÍ

	};

}

#endif