From 6016ece202eef94ed76bd20d4f7879ccc71cc2e6 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 12 Mar 2019 23:08:31 +0800 Subject: *luax --- Source/3rdParty/Luax/luax_reftable.h | 65 ++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Source/3rdParty/Luax/luax_reftable.h (limited to 'Source/3rdParty/Luax/luax_reftable.h') diff --git a/Source/3rdParty/Luax/luax_reftable.h b/Source/3rdParty/Luax/luax_reftable.h new file mode 100644 index 0000000..0ba42f7 --- /dev/null +++ b/Source/3rdParty/Luax/luax_reftable.h @@ -0,0 +1,65 @@ +#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(); + + 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 -- cgit v1.1-26-g67d0