summaryrefslogtreecommitdiff
path: root/Runtime/Scripting/LuaBindRefTable.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-11-15 09:59:32 +0800
committerchai <chaifix@163.com>2020-11-15 09:59:32 +0800
commitd2e4b2839bc7ce874370ff4c52dcfdadf666ff52 (patch)
treeb83e34c2d66cf80b94af5c9a420b6c9c206c138c /Runtime/Scripting/LuaBindRefTable.h
parent64f89347883d519b202711a11d2ea175bd80be37 (diff)
+lua binding
Diffstat (limited to 'Runtime/Scripting/LuaBindRefTable.h')
-rw-r--r--Runtime/Scripting/LuaBindRefTable.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/Runtime/Scripting/LuaBindRefTable.h b/Runtime/Scripting/LuaBindRefTable.h
new file mode 100644
index 0000000..95a21f9
--- /dev/null
+++ b/Runtime/Scripting/LuaBindRefTable.h
@@ -0,0 +1,67 @@
+#ifndef __LUA_BIND_REFTABLE_H__
+#define __LUA_BIND_REFTABLE_H__
+
+#include "LuaBindConfig.h"
+
+namespace LuaBind
+{
+
+ class LuaBindState;
+
+ ///
+ /// ref table 管理,对strong ref table和weak ref table两个table的代理。
+ ///
+ class LuaBindRefTable
+ {
+ public:
+
+ enum
+ {
+ WEAK_KEY = 1,
+ WEAK_VALUE = 1 << 1
+ };
+
+ LuaBindRefTable();
+ ~LuaBindRefTable();
+
+ inline operator bool() { return mState; };
+
+ void Init(LuaBindState& state, cc8* name, cc8* mode = nullptr);
+
+ bool IsKeyWeak();
+ bool IsValueWeak();
+
+ ///
+ /// 对stack[idx]的实体在此ref table中增加一个引用,并返回refID
+ ///
+ int Ref(LuaBindState& state, int idx);
+ void Unref(LuaBindState& state, int refID);
+
+ ///
+ /// 将此 ref table 放在栈顶
+ ///
+ void PushRefTable(LuaBindState& state);
+
+ ///
+ /// 将 reftable[refID] 放在栈顶
+ ///
+ void PushRef(LuaBindState& state, int refID);
+
+ ///
+ /// 清空 ref table,表还留在LUA_REGISTRYINDEX[mName]
+ ///
+ void Clear(LuaBindState& state);
+
+ private:
+
+ friend class LuaBindState;
+
+ lua_State* mState; // 用来做一些确认工作
+ cc8* mName; // ref table的名称
+ int mMode; // ref table的类型
+
+ };
+
+}
+
+#endif \ No newline at end of file