diff options
author | chai <chaifix@163.com> | 2018-08-14 09:26:22 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-08-14 09:26:22 +0800 |
commit | 5162f84be0a4deb447c6ba1226722b049335d525 (patch) | |
tree | 5f7ed0ddc05b1499eaf0607b88fd5cb5e2a961c1 /src/lua/luaopen_types.h | |
parent | 636e766791dc8680d237fafe4ff6dd904e16a860 (diff) |
*update
Diffstat (limited to 'src/lua/luaopen_types.h')
-rw-r--r-- | src/lua/luaopen_types.h | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/src/lua/luaopen_types.h b/src/lua/luaopen_types.h index eef4a3e..587c023 100644 --- a/src/lua/luaopen_types.h +++ b/src/lua/luaopen_types.h @@ -22,16 +22,58 @@ namespace jin namespace lua { + class Object + { + public: + Object() + : count(1) + { + } + + int getReferenceCount() const + { + return count; + } + void retain() + { + ++count; + } + void release() + { + if (--count <= 0) + delete this; + } + + protected: + virtual ~Object() = 0 + { + } + + private: + // reference count + int count; + }; + class Proxy { public: - inline void bind(const void* obj, const char* t) + void bind(Object* obj, const char* t) { object = obj; type = t; } - const void* object; // acctual object binded + void release() + { + if (object != nullptr) + { + object->release(); + object = nullptr; + type = nullptr; + } + } + + Object* object; // acctual object binded const char* type; // type name and metatable name }; |