diff options
author | chai <chaifix@163.com> | 2021-10-22 23:59:54 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-22 23:59:54 +0800 |
commit | 4dafefe46a72ba47468b13d011f8299055081b0f (patch) | |
tree | 2a85835ec4d74fecf3815397b384cefe39d31f56 /Runtime/Lua/LuaBind/LuaBindRef.h | |
parent | 1f18d2afec632aa9361079ca3bcb5a7f2d73db3a (diff) |
*LuaBind
Diffstat (limited to 'Runtime/Lua/LuaBind/LuaBindRef.h')
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindRef.h | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/Runtime/Lua/LuaBind/LuaBindRef.h b/Runtime/Lua/LuaBind/LuaBindRef.h index 7058094..cd2fad1 100644 --- a/Runtime/Lua/LuaBind/LuaBindRef.h +++ b/Runtime/Lua/LuaBind/LuaBindRef.h @@ -11,40 +11,41 @@ namespace LuaBind class Ref { public: - enum RefMode { STRONG_REF, WEAK_REF }; - Ref(RefMode mode = STRONG_REF); + Ref(LuaBind::VM* vm, RefMode mode = STRONG_REF); virtual ~Ref(); operator bool(); // 将栈上的对象添加到全局引用表中 - void SetRef(State& state, int idx); + void SetRef(LuaBind::State& state, int idx); + + // 解除引用 + void UnRef(); // 将引用的对象压入栈 - bool PushRef(State& state); + bool PushRef(LuaBind::State& state); int GetRefID() { return mRefID; } RefMode GetRefMode() { return mMode; } private: - - int mRefID; - RefMode mMode; - + LuaBind::VM* mOwner; // 所属的虚拟机 + RefMode mMode; // 模式 + int mRefID; // 引用ID }; // 强引用,在LUA_REGISTRYINDEX["GAMELAB_UNIVERSAL_STRONG_REFERENCE_TABLE"]里,保证lua object不会被回收 class StrongRef: public Ref { public: - StrongRef(); + StrongRef(LuaBind::VM* vm); }; @@ -52,7 +53,7 @@ namespace LuaBind class WeakRef : public Ref { public: - WeakRef(); + WeakRef(LuaBind::VM* vm); }; |