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/LuaBindRefTable.h | |
parent | 1f18d2afec632aa9361079ca3bcb5a7f2d73db3a (diff) |
*LuaBind
Diffstat (limited to 'Runtime/Lua/LuaBind/LuaBindRefTable.h')
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindRefTable.h | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/Runtime/Lua/LuaBind/LuaBindRefTable.h b/Runtime/Lua/LuaBind/LuaBindRefTable.h index 3401a53..d3de7d6 100644 --- a/Runtime/Lua/LuaBind/LuaBindRefTable.h +++ b/Runtime/Lua/LuaBind/LuaBindRefTable.h @@ -7,8 +7,10 @@ namespace LuaBind { class State; + class VM; // ref table 管理,对strong ref table和weak ref table两个table的代理。 + // 保存在global_State.l_registry,所以是虚拟机下的所有协程共享的 class RefTable { public: @@ -19,19 +21,19 @@ namespace LuaBind WEAK_VALUE = 1 << 1 }; - RefTable(); + RefTable(LuaBind::VM* vm); ~RefTable(); - inline operator bool() { return mState; }; + inline operator bool() { return mVM; }; - void Init(State& state, cc8* name, cc8* mode = nullptr); + void Init(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); + void UnRef(int refID); // 将此 ref table 放在栈顶 void PushRefTable(State& state); @@ -40,13 +42,14 @@ namespace LuaBind void PushRef(State& state, int refID); // 清空 ref table,表还留在LUA_REGISTRYINDEX[mName] - void Clear(State& state); + void Clear(); private: + friend class VM; friend class State; - lua_State* mState; // 用来做一些确认工作 + VM* mVM; // 所属的虚拟机 cc8* mName; // ref table的名称 int mMode; // ref table的类型 |