diff options
author | chai <chaifix@163.com> | 2021-10-18 19:56:41 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-18 19:56:41 +0800 |
commit | 45328cbadd8a946c19a77301f218efbf650e2f28 (patch) | |
tree | 8ec4f3a9737b2cbb9744f8347a56783743be2a4c /Runtime/Lua/LuaBind/LuaBindRefTable.h | |
parent | b5702ece4c2cf751c252e76fb885a7ec41ccabe8 (diff) |
*misc
Diffstat (limited to 'Runtime/Lua/LuaBind/LuaBindRefTable.h')
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindRefTable.h | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/Runtime/Lua/LuaBind/LuaBindRefTable.h b/Runtime/Lua/LuaBind/LuaBindRefTable.h new file mode 100644 index 0000000..0d4c2d4 --- /dev/null +++ b/Runtime/Lua/LuaBind/LuaBindRefTable.h @@ -0,0 +1,67 @@ +#ifndef __LUA_BIND_REFTABLE_H__ +#define __LUA_BIND_REFTABLE_H__ + +#include "LuaBindConfig.h" + +namespace LuaBind +{ + + class State; + + // + // ref table 管理,对strong ref table和weak ref table两个table的代理。 + // + class RefTable + { + public: + + enum + { + WEAK_KEY = 1, + WEAK_VALUE = 1 << 1 + }; + + RefTable(); + ~RefTable(); + + inline operator bool() { return mState; }; + + void Init(State& state, cc8* name, cc8* mode = nullptr); + + bool IsKeyWeak(); + bool IsValueWeak(); + + // + // 对stack[idx]的实体在此ref table中增加一个引用,并返回refID + // + int Ref(State& state, int idx); + void Unref(State& state, int refID); + + // + // 将此 ref table 放在栈顶 + // + void PushRefTable(State& state); + + // + // 将 reftable[refID] 放在栈顶 + // + void PushRef(State& state, int refID); + + // + // 清空 ref table,表还留在LUA_REGISTRYINDEX[mName] + // + void Clear(State& state); + + private: + + friend class State; + + lua_State* mState; // 用来做一些确认工作 + cc8* mName; // ref table的名称 + int mMode; // ref table的类型 + + }; + +} + +#endif
\ No newline at end of file |