From 7322a090355af1989d7a1de0de431b6c89844fe2 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 25 Oct 2018 08:18:13 +0800 Subject: =?UTF-8?q?*=E5=A2=9E=E5=8A=A0lua=E5=AF=BC=E5=87=BA=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lua/common/je_lua_reference.hpp | 88 +++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/lua/common/je_lua_reference.hpp (limited to 'src/lua/common/je_lua_reference.hpp') diff --git a/src/lua/common/je_lua_reference.hpp b/src/lua/common/je_lua_reference.hpp new file mode 100644 index 0000000..ba918bb --- /dev/null +++ b/src/lua/common/je_lua_reference.hpp @@ -0,0 +1,88 @@ +#ifndef __JIN_COMMON_REFERENCE_H +#define __JIN_COMMON_REFERENCE_H + +namespace JinEngine +{ + namespace Lua + { + + /*abstract*/class RefBase + { + public: + void retain() + { + ++count; + } + + void release() + { + if (--count <= 0) + delete this; + } + + // object type string + const char* const type; + + void setUserdata(void* data) + { + userdata = data; + } + + void* getUserdata() + { + return userdata; + } + + protected: + RefBase(void* obj, const char* t) + : count(1) + , object(obj) + , type(t) + { + } + + RefBase(const RefBase&); + + virtual ~RefBase() + { + } + + void* object; + int count; + void* userdata; + }; + + template + class Ref : public RefBase + { + public: + Ref(T* obj, const char* type) + : RefBase(obj, type) + { + } + + ~Ref() + { + T* obj = static_cast(object); + delete obj; + } + + T* operator->() + { + return (T*)object; + } + + T* getObject() + { + return (T*)object; + } + + private: + Ref(const Ref& ref); + + }; + + } +} + +#endif \ No newline at end of file -- cgit v1.1-26-g67d0