summaryrefslogtreecommitdiff
path: root/Runtime/Scripting/luax_reftable.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-10-19 09:13:58 +0800
committerchai <chaifix@163.com>2020-10-19 09:13:58 +0800
commitf0807fc44dde14531759306317611bab87c8fccf (patch)
tree6e78fed61c16a70cda5fa732635f89f9faac9720 /Runtime/Scripting/luax_reftable.h
parent639b34294ffc20721c66db46e59e07d9100ac4b8 (diff)
+gamelab proj
Diffstat (limited to 'Runtime/Scripting/luax_reftable.h')
-rw-r--r--Runtime/Scripting/luax_reftable.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/Runtime/Scripting/luax_reftable.h b/Runtime/Scripting/luax_reftable.h
new file mode 100644
index 0000000..58e4b9c
--- /dev/null
+++ b/Runtime/Scripting/luax_reftable.h
@@ -0,0 +1,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 \ No newline at end of file